diff --git a/src/actions/tutorialActions.js b/src/actions/tutorialActions.js index 147c97b..31e3b6e 100644 --- a/src/actions/tutorialActions.js +++ b/src/actions/tutorialActions.js @@ -1,15 +1,25 @@ import { TUTORIAL_SUCCESS, TUTORIAL_ERROR, TUTORIAL_CHANGE, TUTORIAL_XML, TUTORIAL_ID, TUTORIAL_STEP } from './types'; +import tutorials from '../components/Tutorial/tutorials.json'; + export const tutorialChange = () => (dispatch) => { dispatch({ type: TUTORIAL_CHANGE }); }; -export const tutorialCheck = (status) => (dispatch, getState) => { +export const tutorialCheck = (status, step) => (dispatch, getState) => { var tutorialsStatus = getState().tutorial.status; var id = getState().tutorial.currentId; - tutorialsStatus[id] = {...tutorialsStatus[id], status: status}; + var activeStep = getState().tutorial.activeStep; + var steps = tutorials.filter(tutorial => tutorial.id === id)[0].steps; + var tasks = steps.filter(step => step.type === 'task'); + var tasksIndex = tasks.indexOf(steps[activeStep]); + var tutorialsStatusIndex = tutorialsStatus.findIndex(tutorialStatus => tutorialStatus.id === id); + tutorialsStatus[tutorialsStatusIndex].tasks[tasksIndex] = { + ...tutorialsStatus[tutorialsStatusIndex].tasks[tasksIndex], + type: status + }; dispatch({ type: status === 'success' ? TUTORIAL_SUCCESS : TUTORIAL_ERROR, payload: tutorialsStatus @@ -19,14 +29,23 @@ export const tutorialCheck = (status) => (dispatch, getState) => { export const storeTutorialXml = (code) => (dispatch, getState) => { var id = getState().tutorial.currentId; - var level = getState().tutorial.level; - if(id !== null && level === 'assessment'){ - var tutorialsStatus = getState().tutorial.status; - tutorialsStatus[id] = {...tutorialsStatus[id], xml: code}; - dispatch({ - type: TUTORIAL_XML, - payload: tutorialsStatus - }); + if(id !== null){ + var activeStep = getState().tutorial.activeStep; + var steps = tutorials.filter(tutorial => tutorial.id === id)[0].steps; + if(steps[activeStep].type === 'task'){ + var tutorialsStatus = getState().tutorial.status; + var tasks = steps.filter(step => step.type === 'task'); + var tasksIndex = tasks.indexOf(steps[activeStep]); + var tutorialsStatusIndex = tutorialsStatus.findIndex(tutorialStatus => tutorialStatus.id === id); + tutorialsStatus[tutorialsStatusIndex].tasks[tasksIndex] = { + ...tutorialsStatus[tutorialsStatusIndex].tasks[tasksIndex], + xml: code + }; + dispatch({ + type: TUTORIAL_XML, + payload: tutorialsStatus + }); + } } }; diff --git a/src/components/Tutorial/Assessment.js b/src/components/Tutorial/Assessment.js index 88c3cc9..f15f79b 100644 --- a/src/components/Tutorial/Assessment.js +++ b/src/components/Tutorial/Assessment.js @@ -13,20 +13,26 @@ import Typography from '@material-ui/core/Typography'; class Assessment extends Component { render() { - var currentTutorialId = this.props.currentTutorialId; - var step = this.props.step + var tutorialId = this.props.currentTutorialId; + var steps = this.props.steps; + var currentTask = this.props.step; + var tasks = steps.filter(task => task.type === 'task'); + var taskIndex = tasks.indexOf(currentTask); + var status = this.props.status.filter(status => status.id === tutorialId)[0]; + var statusTask = status.tasks[taskIndex] + return (