From 53b4f5dfeb0780c99e409721d1c9d5a3f29fe121 Mon Sep 17 00:00:00 2001 From: felixerdy Date: Thu, 16 Sep 2021 16:00:27 +0200 Subject: [PATCH] keep workspace code and prepare dialog --- src/components/Blockly/BlocklyWindow.js | 54 +++++++++++++------------ src/components/Home.js | 20 ++++++--- src/components/Project/ProjectHome.js | 50 ++++++++++++++++++++--- 3 files changed, 88 insertions(+), 36 deletions(-) diff --git a/src/components/Blockly/BlocklyWindow.js b/src/components/Blockly/BlocklyWindow.js index 94f9d64..6daabf7 100644 --- a/src/components/Blockly/BlocklyWindow.js +++ b/src/components/Blockly/BlocklyWindow.js @@ -20,16 +20,18 @@ class BlocklyWindow extends Component { componentDidMount() { const workspace = Blockly.getMainWorkspace(); - this.props.onChangeWorkspace({}); - this.props.clearStats(); - workspace.addChangeListener((event) => { - this.props.onChangeWorkspace(event); - // switch on that a block is displayed disabled or not depending on whether it is correctly connected - // for SVG display, a deactivated block in the display is undesirable - if (this.props.blockDisabled) { - Blockly.Events.disableOrphans(event); - } - }); + if (!this.props.readOnly) { + this.props.onChangeWorkspace({}); + this.props.clearStats(); + workspace.addChangeListener((event) => { + this.props.onChangeWorkspace(event); + // switch on that a block is displayed disabled or not depending on whether it is correctly connected + // for SVG display, a deactivated block in the display is undesirable + if (this.props.blockDisabled) { + Blockly.Events.disableOrphans(event); + } + }); + } Blockly.svgResize(workspace); const zoomToFit = new ZoomToFitControl(workspace); zoomToFit.init(); @@ -37,21 +39,23 @@ class BlocklyWindow extends Component { componentDidUpdate(props) { const workspace = Blockly.getMainWorkspace(); - var xml = this.props.initialXml; - // if svg is true, then the update process is done in the BlocklySvg component - if (props.initialXml !== xml && !this.props.svg) { - // guarantees that the current xml-code (this.props.initialXml) is rendered - workspace.clear(); - if (!xml) xml = initialXml; - Blockly.Xml.domToWorkspace(Blockly.Xml.textToDom(xml), workspace); - } - if (props.language !== this.props.language) { - // change language - if (!xml) xml = initialXml; - var xmlDom = Blockly.Xml.textToDom(xml); - Blockly.Xml.clearWorkspaceAndLoadFromXml(xmlDom, workspace); - // var toolbox = workspace.getToolbox(); - // workspace.updateToolbox(toolbox.toolboxDef_); + if (!this.props.readOnly) { + var xml = this.props.initialXml; + // if svg is true, then the update process is done in the BlocklySvg component + if (props.initialXml !== xml && !this.props.svg) { + // guarantees that the current xml-code (this.props.initialXml) is rendered + workspace.clear(); + if (!xml) xml = initialXml; + Blockly.Xml.domToWorkspace(Blockly.Xml.textToDom(xml), workspace); + } + if (props.language !== this.props.language) { + // change language + if (!xml) xml = initialXml; + var xmlDom = Blockly.Xml.textToDom(xml); + Blockly.Xml.clearWorkspaceAndLoadFromXml(xmlDom, workspace); + // var toolbox = workspace.getToolbox(); + // workspace.updateToolbox(toolbox.toolboxDef_); + } } Blockly.svgResize(workspace); } diff --git a/src/components/Home.js b/src/components/Home.js index d169d24..472197c 100644 --- a/src/components/Home.js +++ b/src/components/Home.js @@ -77,7 +77,7 @@ class Home extends Component { componentWillUnmount() { this.props.clearStats(); - this.props.workspaceName(null); + // this.props.workspaceName(null); } onChange = () => { @@ -112,10 +112,17 @@ class Home extends Component {
- {this.props.project ? - < BlocklyWindow blocklyCSS={{ height: '80vH' }} initialXml={this.props.project.xml} /> - : < BlocklyWindow blocklyCSS={{ height: '80vH' }} /> - } + {this.props.project ? ( + + ) : ( + + )}
{this.state.codeOn ? @@ -146,7 +153,8 @@ Home.propTypes = { const mapStateToProps = state => ({ message: state.message, - statistics: state.general.statistics + statistics: state.general.statistics, + workspaceCode: state.workspace.code }); diff --git a/src/components/Project/ProjectHome.js b/src/components/Project/ProjectHome.js index 38ed822..5879c2b 100644 --- a/src/components/Project/ProjectHome.js +++ b/src/components/Project/ProjectHome.js @@ -18,6 +18,8 @@ import Divider from "@material-ui/core/Divider"; import Typography from "@material-ui/core/Typography"; import Backdrop from "@material-ui/core/Backdrop"; import CircularProgress from "@material-ui/core/CircularProgress"; +import Dialog from "../Dialog"; +import Button from "@material-ui/core/Button"; const styles = (theme) => ({ link: { @@ -36,6 +38,7 @@ class ProjectHome extends Component { type: "", key: "", message: "", + dialog: false, }; componentDidMount() { @@ -126,10 +129,24 @@ class ProjectHome extends Component { overflow: "hidden", }} > - { + console.log(this.props.workspaceCode.arduino); + const showDialog = + this.props.workspaceCode.arduino !== + "void setup() { } void loop() { } "; + if (showDialog) + this.setState({ + dialog: true, + }); + else { + this.props.history.push( + `/${ + data === "Projekte" ? "project" : "gallery" + }/${project._id}` + ); + } + }} style={{ textDecoration: "none", color: "inherit" }} >

{project.title}

@@ -139,6 +156,7 @@ class ProjectHome extends Component { {project.description} - + {this.props.user && this.props.user.email === project.creator ? (
@@ -206,6 +224,27 @@ class ProjectHome extends Component { type={this.state.type} key={this.state.key} /> + + + + + } + > + Hello World +
); } @@ -226,6 +265,7 @@ const mapStateToProps = (state) => ({ progress: state.project.progress, user: state.auth.user, message: state.message, + workspaceCode: state.workspace.code, }); export default connect(mapStateToProps, {