From 7300cade5d36f3f9c4736a3685a75ff3f8ac0ed0 Mon Sep 17 00:00:00 2001 From: Delucse <46593742+Delucse@users.noreply.github.com> Date: Sun, 13 Sep 2020 16:02:47 +0200 Subject: [PATCH] each task (step) has its own id within a tutorial --- src/actions/tutorialActions.js | 8 +--- src/components/Tutorial/Assessment.js | 8 ++-- src/components/Tutorial/SolutionCheck.js | 2 +- src/components/Tutorial/StepperHorizontal.js | 7 ++- src/components/Tutorial/StepperVertical.js | 3 +- src/components/Tutorial/Tutorial.js | 4 +- src/components/Tutorial/TutorialHome.js | 1 - src/components/Tutorial/tutorials.json | 47 ++++++++++++++++++++ src/reducers/tutorialReducer.js | 2 - 9 files changed, 59 insertions(+), 23 deletions(-) diff --git a/src/actions/tutorialActions.js b/src/actions/tutorialActions.js index 31e3b6e..b741c3e 100644 --- a/src/actions/tutorialActions.js +++ b/src/actions/tutorialActions.js @@ -11,11 +11,8 @@ export const tutorialChange = () => (dispatch) => { export const tutorialCheck = (status, step) => (dispatch, getState) => { var tutorialsStatus = getState().tutorial.status; var id = getState().tutorial.currentId; - 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); + var tasksIndex = tutorialsStatus[tutorialsStatusIndex].tasks.findIndex(task => task.id === step.id); tutorialsStatus[tutorialsStatusIndex].tasks[tasksIndex] = { ...tutorialsStatus[tutorialsStatusIndex].tasks[tasksIndex], type: status @@ -34,9 +31,8 @@ export const storeTutorialXml = (code) => (dispatch, getState) => { 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); + var tasksIndex = tutorialsStatus[tutorialsStatusIndex].tasks.findIndex(task => task.id === steps[activeStep].id); tutorialsStatus[tutorialsStatusIndex].tasks[tasksIndex] = { ...tutorialsStatus[tutorialsStatusIndex].tasks[tasksIndex], xml: code diff --git a/src/components/Tutorial/Assessment.js b/src/components/Tutorial/Assessment.js index f15f79b..3e2db26 100644 --- a/src/components/Tutorial/Assessment.js +++ b/src/components/Tutorial/Assessment.js @@ -14,13 +14,11 @@ class Assessment extends Component { render() { 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] - + var taskIndex = status.tasks.findIndex(task => task.id === currentTask.id); + var statusTask = status.tasks[taskIndex]; + return (