From 08dab82d002353f2f1d54d6b652ce1bcc597f86d Mon Sep 17 00:00:00 2001 From: Delucse <46593742+Delucse@users.noreply.github.com> Date: Mon, 10 Aug 2020 10:06:34 +0200 Subject: [PATCH] showing CircularProgress while compiling --- src/components/Blockly/BlocklyComponent.css | 2 +- src/components/Compile.js | 94 +++++++++++++++++++++ src/components/WorkspaceFunc.js | 28 +----- 3 files changed, 97 insertions(+), 27 deletions(-) create mode 100644 src/components/Compile.js diff --git a/src/components/Blockly/BlocklyComponent.css b/src/components/Blockly/BlocklyComponent.css index acc2ee2..8705fbc 100644 --- a/src/components/Blockly/BlocklyComponent.css +++ b/src/components/Blockly/BlocklyComponent.css @@ -1,6 +1,6 @@ #blocklyDiv { height: 100%; - min-height: 700px; + min-height: 500px; width: 100%; /* border: 1px solid #4EAF47; */ position: relative; diff --git a/src/components/Compile.js b/src/components/Compile.js new file mode 100644 index 0000000..1d0f15c --- /dev/null +++ b/src/components/Compile.js @@ -0,0 +1,94 @@ +import React, { Component } from 'react'; +import PropTypes from 'prop-types'; +import { connect } from 'react-redux'; + +import { withStyles } from '@material-ui/core/styles'; +import Button from '@material-ui/core/Button'; +import Backdrop from '@material-ui/core/Backdrop'; +import CircularProgress from '@material-ui/core/CircularProgress'; +import DialogTitle from '@material-ui/core/DialogTitle'; +import DialogContent from '@material-ui/core/DialogContent'; +import DialogActions from '@material-ui/core/DialogActions'; +import Dialog from '@material-ui/core/Dialog'; + +const styles = (theme) => ({ + backdrop: { + zIndex: theme.zIndex.drawer + 1, + color: '#fff', + } +}); + + +class Compile extends Component { + + state = { + progress: false, + open: false + } + + compile = () => { + const data = { + "board": process.env.REACT_APP_BOARD, + "sketch": this.props.arduino + }; + this.setState({ progress: true }); + 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) + }) + .catch(err => { + console.log(err); + this.setState({ progress: false, open: true }); + }); + } + + 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'); + this.setState({ progress: false }); + } + + toggleDialog = () => { + this.setState({ open: !this.state }); + } + + render() { + return ( +