stored xml in tutorial redux store
This commit is contained in:
		
							parent
							
								
									7e0fbf1f75
								
							
						
					
					
						commit
						eea893a071
					
				| @ -6,8 +6,9 @@ export const tutorialChange = () => (dispatch) => { | |||||||
|   }); |   }); | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| export const tutorialCheck = (id, status) => (dispatch, getState) => { | export const tutorialCheck = (status) => (dispatch, getState) => { | ||||||
|   var tutorialsStatus = getState().tutorial.status; |   var tutorialsStatus = getState().tutorial.status; | ||||||
|  |   var id = getState().tutorial.currentId; | ||||||
|   tutorialsStatus[id] = {...tutorialsStatus[id], status: status}; |   tutorialsStatus[id] = {...tutorialsStatus[id], status: status}; | ||||||
|   dispatch({ |   dispatch({ | ||||||
|     type: status === 'success' ? TUTORIAL_SUCCESS : TUTORIAL_ERROR, |     type: status === 'success' ? TUTORIAL_SUCCESS : TUTORIAL_ERROR, | ||||||
| @ -16,13 +17,16 @@ export const tutorialCheck = (id, status) => (dispatch, getState) => { | |||||||
|   dispatch(tutorialChange()); |   dispatch(tutorialChange()); | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| export const storeTutorialXml = (id) => (dispatch, getState) => { | export const storeTutorialXml = (code) => (dispatch, getState) => { | ||||||
|   var tutorialsStatus = getState().tutorial.status; |   var tutorialsStatus = getState().tutorial.status; | ||||||
|   tutorialsStatus[id] = {...tutorialsStatus[id]}; |   var id = getState().tutorial.currentId; | ||||||
|   dispatch({ |   if(id){ | ||||||
|     type: TUTORIAL_XML, |     tutorialsStatus[id] = {...tutorialsStatus[id], xml: code}; | ||||||
|     payload: tutorialsStatus |     dispatch({ | ||||||
|   }); |       type: TUTORIAL_XML, | ||||||
|  |       payload: tutorialsStatus | ||||||
|  |     }); | ||||||
|  |   } | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| export const tutorialId = (id) => (dispatch) => { | export const tutorialId = (id) => (dispatch) => { | ||||||
|  | |||||||
| @ -2,6 +2,8 @@ import { NEW_CODE, CHANGE_WORKSPACE, CREATE_BLOCK, MOVE_BLOCK, CHANGE_BLOCK, DEL | |||||||
| 
 | 
 | ||||||
| import * as Blockly from 'blockly/core'; | import * as Blockly from 'blockly/core'; | ||||||
| 
 | 
 | ||||||
|  | import { storeTutorialXml } from './tutorialActions'; | ||||||
|  | 
 | ||||||
| export const workspaceChange = () => (dispatch) => { | export const workspaceChange = () => (dispatch) => { | ||||||
|   dispatch({ |   dispatch({ | ||||||
|     type: CHANGE_WORKSPACE |     type: CHANGE_WORKSPACE | ||||||
| @ -18,11 +20,13 @@ export const onChangeCode = () => (dispatch, getState) => { | |||||||
|     type: NEW_CODE, |     type: NEW_CODE, | ||||||
|     payload: code |     payload: code | ||||||
|   }); |   }); | ||||||
|  |   return code; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| export const onChangeWorkspace = (event) => (dispatch, getState) => { | export const onChangeWorkspace = (event) => (dispatch, getState) => { | ||||||
|   dispatch(workspaceChange()); |   dispatch(workspaceChange()); | ||||||
|   dispatch(onChangeCode()); |   var code = dispatch(onChangeCode()); | ||||||
|  |   dispatch(storeTutorialXml(code.xml)); | ||||||
|   var stats = getState().workspace.stats; |   var stats = getState().workspace.stats; | ||||||
|   if (event.type === Blockly.Events.BLOCK_CREATE) { |   if (event.type === Blockly.Events.BLOCK_CREATE) { | ||||||
|     stats.create += event.ids.length; |     stats.create += event.ids.length; | ||||||
|  | |||||||
| @ -54,7 +54,7 @@ class BlocklyWindow extends Component { | |||||||
|           drag: true, |           drag: true, | ||||||
|           wheel: false |           wheel: false | ||||||
|         }} |         }} | ||||||
|         initialXml={initialXml} |         initialXml={this.props.initialXml ? this.props.initialXml : initialXml} | ||||||
|       > |       > | ||||||
| 
 | 
 | ||||||
|       </BlocklyComponent > |       </BlocklyComponent > | ||||||
|  | |||||||
| @ -83,7 +83,6 @@ class CodeViewer extends Component { | |||||||
|   render() { |   render() { | ||||||
|     var curlyBrackets = '{ }'; |     var curlyBrackets = '{ }'; | ||||||
|     var unequal = '<>'; |     var unequal = '<>'; | ||||||
|     console.log('render', this.myDiv); |  | ||||||
|     return ( |     return ( | ||||||
|       <Card style={{height: '100%', maxHeight: '500px'}} ref={this.myDiv}> |       <Card style={{height: '100%', maxHeight: '500px'}} ref={this.myDiv}> | ||||||
|         <Accordion |         <Accordion | ||||||
|  | |||||||
| @ -50,7 +50,7 @@ class SolutionCheck extends Component { | |||||||
|   check = () => { |   check = () => { | ||||||
|     const workspace = Blockly.getMainWorkspace(); |     const workspace = Blockly.getMainWorkspace(); | ||||||
|     var msg = tutorials[this.props.currentTutorialId].test(workspace); |     var msg = tutorials[this.props.currentTutorialId].test(workspace); | ||||||
|     this.props.tutorialCheck(this.props.currentTutorialId, msg.type); |     this.props.tutorialCheck(msg.type); | ||||||
|     this.setState({ msg, open: true }); |     this.setState({ msg, open: true }); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -98,16 +98,16 @@ class StepperVertical extends Component { | |||||||
|   componentDidUpdate(props){ |   componentDidUpdate(props){ | ||||||
|     if(props.currentTutorialId !== this.props.currentTutorialId){ |     if(props.currentTutorialId !== this.props.currentTutorialId){ | ||||||
|       this.setState({ |       this.setState({ | ||||||
|         tutorialArray: props.currentTutorialId === 0 ? |         tutorialArray: this.props.currentTutorialId === 0 ? | ||||||
|                         tutorials.slice(props.currentTutorialId, props.currentTutorialId+5) |                         tutorials.slice(this.props.currentTutorialId, this.props.currentTutorialId+5) | ||||||
|                         : props.currentTutorialId === 1 ? |                         : this.props.currentTutorialId === 1 ? | ||||||
|                             tutorials.slice(props.currentTutorialId-1, props.currentTutorialId+4) |                             tutorials.slice(this.props.currentTutorialId-1, this.props.currentTutorialId+4) | ||||||
|                             : props.currentTutorialId === tutorials.length-1 ? |                             : this.props.currentTutorialId === tutorials.length-1 ? | ||||||
|                                   tutorials.slice(props.currentTutorialId-4, props.currentTutorialId+5) |                                   tutorials.slice(this.props.currentTutorialId-4, this.props.currentTutorialId+5) | ||||||
|                                 : props.currentTutorialId === tutorials.length-2 ? |                                 : this.props.currentTutorialId === tutorials.length-2 ? | ||||||
|                                       tutorials.slice(props.currentTutorialId-3, props.currentTutorialId+4) |                                       tutorials.slice(this.props.currentTutorialId-3, this.props.currentTutorialId+4) | ||||||
|                                     : tutorials.slice(props.currentTutorialId-2, props.currentTutorialId+3), |                                     : tutorials.slice(this.props.currentTutorialId-2, this.props.currentTutorialId+3), | ||||||
|         selectedVerticalTutorialId: props.currentTutorialId |         selectedVerticalTutorialId: this.props.currentTutorialId | ||||||
|       }); |       }); | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  | |||||||
| @ -36,6 +36,10 @@ class Tutorial extends Component { | |||||||
|     } |     } | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  |   componentWillUnmount(){ | ||||||
|  |     this.props.tutorialId(null); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|   onChange = (e, value) => { |   onChange = (e, value) => { | ||||||
|     this.setState({ value: value }); |     this.setState({ value: value }); | ||||||
|   } |   } | ||||||
| @ -74,7 +78,7 @@ class Tutorial extends Component { | |||||||
|                   <Grid container spacing={2}> |                   <Grid container spacing={2}> | ||||||
|                     <Grid item xs={12} md={6} lg={8} style={{ position: 'relative' }}> |                     <Grid item xs={12} md={6} lg={8} style={{ position: 'relative' }}> | ||||||
|                       <SolutionCheck /> |                       <SolutionCheck /> | ||||||
|                       <BlocklyWindow /> |                       <BlocklyWindow initialXml={this.props.status[currentTutorialId].xml ? this.props.status[currentTutorialId].xml : null}/> | ||||||
|                     </Grid> |                     </Grid> | ||||||
|                     <Grid item xs={12} md={6} lg={4}> |                     <Grid item xs={12} md={6} lg={4}> | ||||||
|                       <Card style={{height: 'calc(50% - 30px)', padding: '10px', marginBottom: '10px'}}> |                       <Card style={{height: 'calc(50% - 30px)', padding: '10px', marginBottom: '10px'}}> | ||||||
| @ -96,10 +100,14 @@ class Tutorial extends Component { | |||||||
| 
 | 
 | ||||||
| Tutorial.propTypes = { | Tutorial.propTypes = { | ||||||
|   tutorialId: PropTypes.func.isRequired, |   tutorialId: PropTypes.func.isRequired, | ||||||
|   currentTutorialId: PropTypes.number.isRequired |   currentTutorialId: PropTypes.number.isRequired, | ||||||
|  |   status: PropTypes.array.isRequired, | ||||||
|  |   change: PropTypes.number.isRequired | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| const mapStateToProps = state => ({ | const mapStateToProps = state => ({ | ||||||
|  |   change: state.tutorial.change, | ||||||
|  |   status: state.tutorial.status, | ||||||
|   currentTutorialId: state.tutorial.currentId |   currentTutorialId: state.tutorial.currentId | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user