no need for pdf-js

This commit is contained in:
Thomas Ruoff
2017-02-19 22:06:22 +01:00
parent 8542c0bf2d
commit 32d226259a
8 changed files with 58 additions and 55078 deletions

View File

@@ -2,21 +2,27 @@ import { Component, h } from 'preact';
import PDF from 'react-pdf';
import Input from '../components/Input';
import TextAreaInput from '../components/TextAreaInput';
import Button from '../components/Button';
import Preview from '../components/Preview';
function toBase64(arrayBuffer) {
return btoa(String.fromCharCode(...new Uint8Array(arrayBuffer)));
}
import {generatePdf} from '../../apiHelper';
class Home extends Component {
render(props) {
const component = this;
return (
<div>
<TextAreaInput
name="address"
text="Adresse"
onchange={this._onChange.bind(this)}
value={props.address}
/>
<Input
name="subject"
text="Betreff"
onChange={this._onChange.bind(this)}
onchange={this._onChange.bind(this)}
value={props.subject}
/>
<Button onClick={this._onGenerate.bind(this)} text="Generiere"/>
@@ -25,6 +31,21 @@ class Home extends Component {
);
}
_onGenerate() {
generatePdf(this.state)
.then((data) => {
const {id} = data;
this.setState({
pdfUrl: `//localhost:5000/pdf/${id}`
});
})
.catch((error) => {
this.setState({
pdfUrl: null
});
});
}
_onChange(name, event) {
if (!name) {
return;
@@ -33,32 +54,6 @@ class Home extends Component {
this.setState({[name]: value || null})
}
_onGenerate(name, event){
var component = this;
fetch('//localhost:5000/pdf/generate/brief', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(this.state)
}).then(function(res) {
if (res.status !== 200) {
console.log('request failed');
return;
}
return res.json();
}).then(function(data) {
const {id} = data;
component.setState({
pdfUrl: `//localhost:5000/pdf/${id}`
});
}).catch(function(error) {
component.setState({
pdfUrl: null
})
});
}
}
export default Home;