import React, { Component } from "react"; import PropTypes from "prop-types"; import { connect } from "react-redux"; import { workspaceName } from "../../actions/workspaceActions"; import { detectWhitespacesAndReturnReadableResult } from "../../helpers/whitespace"; 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 IconButton from "@material-ui/core/IconButton"; import Tooltip from "@material-ui/core/Tooltip"; import Divider from "@material-ui/core/Divider"; import { faClipboardCheck } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import * as Blockly from "blockly/core"; import Copy from "../copy.svg"; import Prism from "prismjs"; import "prismjs/themes/prism.css"; import "prismjs/plugins/line-numbers/prism-line-numbers"; import "prismjs/plugins/line-numbers/prism-line-numbers.css"; import MuiDrawer from "@material-ui/core/Drawer"; import Dialog from "../Dialog"; const styles = (theme) => ({ backdrop: { zIndex: theme.zIndex.drawer + 1, color: "#fff", }, iconButton: { backgroundColor: theme.palette.button.compile, color: theme.palette.primary.contrastText, width: "40px", height: "40px", "&:hover": { backgroundColor: theme.palette.button.compile, color: theme.palette.primary.contrastText, }, }, button: { backgroundColor: theme.palette.button.compile, color: theme.palette.primary.contrastText, "&:hover": { backgroundColor: theme.palette.button.compile, color: theme.palette.primary.contrastText, }, }, }); const Drawer = withStyles((theme) => ({ paperAnchorBottom: { backgroundColor: "black", height: "20vH", }, }))(MuiDrawer); class Compile extends Component { constructor(props) { super(props); this.state = { progress: false, open: false, file: false, title: "", content: "", name: props.name, error: "", appLink: "", appDialog: false, }; } componentDidMount() { Prism.highlightAll(); } componentDidUpdate(props) { if (props.name !== this.props.name) { this.setState({ name: this.props.name }); } Prism.highlightAll(); } compile = () => { this.setState({ progress: true }); 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); if (data.code === "Internal Server Error") { this.setState({ progress: false, file: false, open: true, title: Blockly.Msg.compiledialog_headline, content: Blockly.Msg.compiledialog_text, error: data.message, }); } this.setState({ id: data.data.id }, () => { this.createFileName(); }); }) .catch((err) => { console.log(err); //this.setState({ progress: false, file: false, open: true, title: Blockly.Msg.compiledialog_headline, content: Blockly.Msg.compiledialog_text }); }); }; download = () => { const id = this.state.id; const filename = detectWhitespacesAndReturnReadableResult(this.state.name); this.toggleDialog(); this.props.workspaceName(this.state.name); 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, progress: false, appDialog: false }); }; createFileName = () => { if (this.props.platform === "iOS") { this.setState({ link: `blocklyconnect-app://${this.state.name}/${this.state.id}`, }); this.setState({ appDialog: true }); } else { if (this.state.name) { this.download(); } else { this.setState({ file: true, open: true, title: "Projekt kompilieren", content: "Bitte gib einen Namen für die Bennenung des zu kompilierenden Programms ein und bestätige diesen mit einem Klick auf 'Eingabe'.", }); } } // if (this.state.name) { // this.download(); // } else { // this.setState({ // file: true, // open: true, // title: "Projekt kompilieren", // content: // "Bitte gib einen Namen für die Bennenung des zu kompilierenden Programms ein und bestätige diesen mit einem Klick auf 'Eingabe'.", // }); // } }; setFileName = (e) => { this.setState({ name: e.target.value }); }; toggleDrawer = (anchor, open) => (event) => { if ( event.type === "keydown" && (event.key === "Tab" || event.key === "Shift") ) { return; } this.setState({ open: false }); }; render() { return (
{Blockly.Msg.compile_overlay_text}
{Blockly.Msg.compile_overlay_help} FAQ
{Blockly.Msg.drawer_ideerror_text}
{" "} {`${this.state.error}`}{" "}