online compiling

This commit is contained in:
felixerdy 2020-08-03 16:38:18 +02:00
parent fd4afa9e60
commit ddd3fa1fcf
2 changed files with 28 additions and 0 deletions

2
.env Normal file
View File

@ -0,0 +1,2 @@
REACT_APP_COMPILER_URL=https://compiler.sensebox.de
REACT_APP_BOARD=sensebox-mcu

View File

@ -30,6 +30,29 @@ class WorkspaceFunc extends Component {
this.setState({ open: !this.state });
}
compile = () => {
const data = {
"board": process.env.REACT_APP_BOARD,
"sketch": this.props.arduino
};
fetch(`${process.env.REACT_APP_COMPILER_URL}/compile`, {
method: "POST",
headers: {'Content-Type': 'application/json'},
body: JSON.stringify(data)
})
.then(response => response.json())
.then(data => {
console.log(data)
this.download(data.data.id)
});
}
download = (id) => {
const filename = 'sketch'
window.open(`${process.env.REACT_APP_COMPILER_URL}/download?id=${id}&board=${process.env.REACT_APP_BOARD}&filename=${filename}`, '_self');
}
render() {
return (
<div style={{ marginTop: '20px' }}>
@ -51,6 +74,9 @@ class WorkspaceFunc extends Component {
Get XML Code
</Button>
<MaxBlocks />
<Button style={{ float: 'right', color: 'white' }} variant="contained" color="primary" onClick={() => this.compile()}>
Compile
</Button>
</div>
);
};