diff --git a/src/components/Blockly/BlocklyWindow.js b/src/components/Blockly/BlocklyWindow.js index 0b0cf02..7a807a9 100644 --- a/src/components/Blockly/BlocklyWindow.js +++ b/src/components/Blockly/BlocklyWindow.js @@ -21,9 +21,18 @@ class BlocklyWindow extends Component { } componentDidMount() { + console.log(this.props); const workspace = Blockly.getMainWorkspace(); - this.props.onChangeWorkspace({}); - this.props.clearStats(); + + if (this.props.workspaceXML !== "") { + Blockly.Xml.clearWorkspaceAndLoadFromXml( + Blockly.Xml.textToDom(this.props.workspaceXML), + workspace + ); + } else { + 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 @@ -38,6 +47,8 @@ class BlocklyWindow extends Component { componentDidUpdate(props) { const workspace = Blockly.getMainWorkspace(); var xml = this.props.initialXml; + console.log(xml) + console.log(this.props.xml) // 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 @@ -45,6 +56,7 @@ class BlocklyWindow extends Component { if (!xml) xml = initialXml; Blockly.Xml.domToWorkspace(Blockly.Xml.textToDom(xml), workspace); } + if (props.language !== this.props.language) { // change language if (!xml) xml = initialXml; @@ -101,12 +113,14 @@ BlocklyWindow.propTypes = { onChangeWorkspace: PropTypes.func.isRequired, clearStats: PropTypes.func.isRequired, renderer: PropTypes.string.isRequired, - language: PropTypes.string.isRequired + language: PropTypes.string.isRequired, + workspaceXML: PropTypes.string.isRequired, }; const mapStateToProps = state => ({ renderer: state.general.renderer, - language: state.general.language + language: state.general.language.Blockly, + workspaceXML: state.workspace.code.xml, }); export default connect(mapStateToProps, { onChangeWorkspace, clearStats })(BlocklyWindow); diff --git a/src/components/Home.js b/src/components/Home.js index d169d24..52ccebe 100644 --- a/src/components/Home.js +++ b/src/components/Home.js @@ -114,7 +114,7 @@ class Home extends Component {