stored xml in tutorial redux store

This commit is contained in:
Delucse
2020-09-08 14:43:30 +02:00
parent 7e0fbf1f75
commit eea893a071
7 changed files with 38 additions and 23 deletions
+11 -7
View File
@@ -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 id = getState().tutorial.currentId;
tutorialsStatus[id] = {...tutorialsStatus[id], status: status};
dispatch({
type: status === 'success' ? TUTORIAL_SUCCESS : TUTORIAL_ERROR,
@@ -16,13 +17,16 @@ export const tutorialCheck = (id, status) => (dispatch, getState) => {
dispatch(tutorialChange());
};
export const storeTutorialXml = (id) => (dispatch, getState) => {
export const storeTutorialXml = (code) => (dispatch, getState) => {
var tutorialsStatus = getState().tutorial.status;
tutorialsStatus[id] = {...tutorialsStatus[id]};
dispatch({
type: TUTORIAL_XML,
payload: tutorialsStatus
});
var id = getState().tutorial.currentId;
if(id){
tutorialsStatus[id] = {...tutorialsStatus[id], xml: code};
dispatch({
type: TUTORIAL_XML,
payload: tutorialsStatus
});
}
};
export const tutorialId = (id) => (dispatch) => {
+5 -1
View File
@@ -2,6 +2,8 @@ import { NEW_CODE, CHANGE_WORKSPACE, CREATE_BLOCK, MOVE_BLOCK, CHANGE_BLOCK, DEL
import * as Blockly from 'blockly/core';
import { storeTutorialXml } from './tutorialActions';
export const workspaceChange = () => (dispatch) => {
dispatch({
type: CHANGE_WORKSPACE
@@ -18,11 +20,13 @@ export const onChangeCode = () => (dispatch, getState) => {
type: NEW_CODE,
payload: code
});
return code;
};
export const onChangeWorkspace = (event) => (dispatch, getState) => {
dispatch(workspaceChange());
dispatch(onChangeCode());
var code = dispatch(onChangeCode());
dispatch(storeTutorialXml(code.xml));
var stats = getState().workspace.stats;
if (event.type === Blockly.Events.BLOCK_CREATE) {
stats.create += event.ids.length;