@@ -27,6 +27,70 @@ export default {
27
27
},
28
28
}),
29
29
// @ts-ignore
30
+ updateStepPosition: assign({
31
+ position: (context: CR.MachineContext, event: CR.MachineEvent): CR.Position => {
32
+ const position: CR.Position = context.position
33
+ // merge in the updated position
34
+ // sent with the test to ensure consistency
35
+ const steps: G.Step[] = context.tutorial.version
36
+ .levels.find((l: G.Level) => l.id === position.levelId)
37
+ .stages.find((s: G.Stage) => s.id === position.stageId)
38
+ .steps
39
+
40
+ const stepIndex = steps.findIndex((s: G.Step) => s.id === position.stepId)
41
+ const step: G.Step = steps[stepIndex + 1]
42
+
43
+ console.log('step load next', step.id, position.stepId)
44
+
45
+ return {
46
+ ...position,
47
+ stepId: step.id
48
+ }
49
+ },
50
+ }),
51
+ // @ts-ignore
52
+ updateStagePosition: assign({
53
+ position: (context: CR.MachineContext, event: CR.MachineEvent): CR.Position => {
54
+ const position: CR.Position = context.position
55
+ // merge in the updated position
56
+ // sent with the test to ensure consistency
57
+ const stages: G.Stage[] = context.tutorial.version
58
+ .levels.find((l: G.Level) => l.id === position.levelId)
59
+ .stages
60
+
61
+ const stageIndex = stages.findIndex((s: G.Stage) => s.id === position.stageId)
62
+ const stage: G.Stage = stages[stageIndex + 1]
63
+
64
+ console.log('stage load next', stage.id, position.stageId)
65
+
66
+ return {
67
+ ...position,
68
+ stageId: stage.id,
69
+ stepId: stage.steps[0].id,
70
+ }
71
+ },
72
+ }),
73
+ // @ts-ignore
74
+ updateLevelPosition: assign({
75
+ position: (context: CR.MachineContext, event: CR.MachineEvent): CR.Position => {
76
+ const position: CR.Position = context.position
77
+ // merge in the updated position
78
+ // sent with the test to ensure consistency
79
+ const levels: G.Level[] = context.tutorial.version.levels
80
+
81
+ const levelIndex = levels.findIndex((l: G.Level) => l.id === position.levelId)
82
+ const level: G.Level = levels[levelIndex + 1]
83
+
84
+ console.log('level load next', level.id, position.levelId)
85
+
86
+ return {
87
+ levelId: level.id,
88
+ stageId: level.stages[0].id,
89
+ stepId: level.stages[0].steps[0].id,
90
+ }
91
+ },
92
+ }),
93
+ // @ts-ignore
30
94
updateStepProgress: assign({
31
95
progress: (context: CR.MachineContext, event: CR.MachineEvent): CR.Progress => {
32
96
// update progress by tracking completed
@@ -53,27 +117,4 @@ export default {
53
117
return progress
54
118
},
55
119
}),
56
- //@ts -ignore
57
- stepLoadNext :assign ( {
58
- position :( context :CR . MachineContext , event :CR . MachineEvent ) :CR . Position => {
59
- const position :CR . Position = context . position
60
- // merge in the updated position
61
- // sent with the test to ensure consistency
62
- const steps :G . Step [ ] = context . tutorial . version
63
- . levels . find ( ( l :G . Level ) => l . id === position . levelId )
64
- . stages . find ( ( s :G . Stage ) => s . id === position . stageId )
65
- . steps
66
-
67
- const stepIndex = steps . findIndex ( ( s :G . Step ) => s . id === position . stepId )
68
- console . log ( 'step index' , stepIndex )
69
- const step :G . Step = steps [ stepIndex + 1 ]
70
-
71
- console . log ( 'step load next' , step . id , position . stepId )
72
-
73
- return {
74
- ...position ,
75
- stepId :step . id
76
- }
77
- } ,
78
- } )
79
120
}