Skip to content

Commit a7a7a94

Browse files
committed
fix up step progress
1 parent da942ac commit a7a7a94

File tree

3 files changed

+50
-10
lines changed

3 files changed

+50
-10
lines changed

web-app/src/containers/Tutorial/StagePage/index.tsx

+27-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ interface PageProps {
1212
const StageSummaryPageContainer = (props: PageProps) => {
1313
const { tutorial, position, progress } = props.context
1414

15-
const stage: G.Stage = tutorial.version.levels.find((l: G.Level) => l.id === position.levelId).stages.find((s: G.Stage) => s.id === position.stageId)
15+
const stage: G.Stage = tutorial.version
16+
.levels.find((l: G.Level) => l.id === position.levelId)
17+
.stages.find((s: G.Stage) => s.id === position.stageId)
1618

1719
const onContinue = (): void => {
1820
props.send({
@@ -32,7 +34,7 @@ const StageSummaryPageContainer = (props: PageProps) => {
3234
})
3335
}
3436

35-
stage.steps.forEach((step: G.Step) => {
37+
stage.steps.map((step: G.Step) => {
3638
if (step.id === position.stepId) {
3739
step.status = 'ACTIVE'
3840
} else if (progress.steps[step.id]) {
@@ -46,3 +48,26 @@ const StageSummaryPageContainer = (props: PageProps) => {
4648
}
4749

4850
export default StageSummaryPageContainer
51+
52+
/*
53+
const formattedStage = {
54+
...stage,
55+
steps: stage.steps.map((step: G.Step) => {
56+
if (step.id === position.stepId) {
57+
return {
58+
...step,
59+
status: 'ACTIVE'
60+
}
61+
} else if (progress.steps[step.id]) {
62+
return {
63+
...step,
64+
status: 'COMPLETE'
65+
}
66+
} else {
67+
return {
68+
...step,
69+
status: 'INCOMPLETE'
70+
}
71+
}
72+
})
73+
*/

web-app/src/services/state/actions/context.ts

+13-3
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,23 @@ export default {
4242
// @ts-ignore
4343
stepLoadNext: assign({
4444
position: (context: CR.MachineContext, event: CR.MachineEvent): CR.Position => {
45-
const currentPosition: CR.Position = context.position
45+
const position: CR.Position = context.position
4646
// merge in the updated position
4747
// sent with the test to ensure consistency
48-
console.log('should calculate next step')
48+
const steps: G.Step[] = context.tutorial.version
49+
.levels.find((l: G.Level) => l.id === position.levelId)
50+
.stages.find((s: G.Stage) => s.id === position.stageId)
51+
.steps
52+
53+
const stepIndex = steps.findIndex((s: G.Step) => s.id === position.stepId)
54+
console.log('step index', stepIndex)
55+
const step: G.Step = steps[stepIndex + 1]
56+
57+
console.log('step load next', step.id, position.stepId)
4958

5059
return {
51-
...currentPosition,
60+
...position,
61+
stepId: step.id
5262
}
5363
},
5464
})

web-app/src/services/state/guards/index.ts

+10-5
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,30 @@ export default {
66
hasNextStep: (context: CR.MachineContext): boolean => {
77
const {tutorial, position} = context
88
// TODO: protect against errors
9-
const steps: G.Step[] = tutorial.version.levels.find((l: G.Level) => l.id === position.levelId).stages.find((s: G.Stage) => s.id === position.stageId).steps
9+
const steps: G.Step[] = tutorial.version
10+
.levels.find((l: G.Level) => l.id === position.levelId)
11+
.stages.find((s: G.Stage) => s.id === position.stageId)
12+
.steps
1013

1114
// TODO: verify not -1
12-
return !(steps.indexOf(position.stepId) === steps.length - 1)
15+
return !(steps.findIndex((s: G.Step) => s.id === position.stepId) === steps.length - 1)
1316
},
1417
hasNextStage: (context: CR.MachineContext): boolean => {
1518
const {tutorial, position} = context
1619
// TODO: protect against errors
17-
const stages: G.Stage[] = tutorial.version.levels.find((l: G.Level) => l.id === position.levelId).stages
20+
const stages: G.Stage[] = tutorial.version
21+
.levels.find((l: G.Level) => l.id === position.levelId)
22+
.stages
1823

1924
// TODO: verify not -1
20-
return !(stages.indexOf(position.stageId) === stages.length - 1)
25+
return !(stages.findIndex((s: G.Stage) => s.id === position.stageId) === stages.length - 1)
2126
},
2227
hasNextLevel: (context: CR.MachineContext): boolean => {
2328
const {tutorial, position} = context
2429
// TODO: protect against errors
2530
const levels: G.Level[] = tutorial.version.levels
2631

2732
// TODO: verify not -1
28-
return !(levels.indexOf(position.levelId) === levels.length - 1)
33+
return !(levels.findIndex((l: G.Level) => l.id === position.levelId) === levels.length - 1)
2934
},
3035
}

0 commit comments

Comments
 (0)