1
- import * as CR from 'typings'
1
+ import * as T from 'typings'
2
2
import * as G from 'typings/graphql'
3
3
import { assign , send , ActionFunctionMap } from 'xstate'
4
4
import * as selectors from '../../selectors'
5
5
import onError from '../../../services/sentry/onError'
6
6
7
- const contextActions :ActionFunctionMap < CR . MachineContext , CR . MachineEvent > = {
7
+ const contextActions :ActionFunctionMap < T . MachineContext , T . MachineEvent > = {
8
8
//@ts -ignore
9
9
setEnv :assign ( {
10
- env :( context :CR . MachineContext , event :CR . MachineEvent ) => {
10
+ env :( context :T . MachineContext , event :T . MachineEvent ) => {
11
11
return {
12
12
...context . env ,
13
13
...event . payload . env ,
@@ -16,35 +16,35 @@ const contextActions: ActionFunctionMap<CR.MachineContext, CR.MachineEvent> = {
16
16
} ) ,
17
17
//@ts -ignore
18
18
continueTutorial :assign ( {
19
- tutorial :( context :CR . MachineContext , event :CR . MachineEvent ) => {
19
+ tutorial :( context :T . MachineContext , event :T . MachineEvent ) => {
20
20
return event . payload . tutorial
21
21
} ,
22
- progress :( context :CR . MachineContext , event :CR . MachineEvent ) => {
22
+ progress :( context :T . MachineContext , event :T . MachineEvent ) => {
23
23
return event . payload . progress
24
24
} ,
25
- position :( context :CR . MachineContext , event :CR . MachineEvent ) => {
25
+ position :( context :T . MachineContext , event :T . MachineEvent ) => {
26
26
return event . payload . position
27
27
} ,
28
28
} ) ,
29
29
//@ts -ignore
30
30
selectTutorialById :assign ( {
31
- tutorial :( context :CR . MachineContext , event :CR . MachineEvent ) :any => {
31
+ tutorial :( context :T . MachineContext , event :T . MachineEvent ) :any => {
32
32
return event . payload . tutorial
33
33
} ,
34
34
} ) ,
35
35
//@ts -ignore
36
36
startNewTutorial :assign ( {
37
- position :( context :CR . MachineContext , event :CR . MachineEvent ) :CR . Position => {
38
- const position :CR . Position = selectors . initialPosition ( context )
37
+ position :( context :T . MachineContext , event :T . MachineEvent ) :any => {
38
+ const position :T . Position = selectors . initialPosition ( context )
39
39
return position
40
40
} ,
41
- progress :( ) :CR . Progress => {
41
+ progress :( ) :T . Progress => {
42
42
return { levels :{ } , steps :{ } , complete :false }
43
43
} ,
44
44
} ) ,
45
45
//@ts -ignore
46
46
updateStepPosition :assign ( {
47
- position :( context :CR . MachineContext , event :CR . MachineEvent ) :CR . Position => {
47
+ position :( context :T . MachineContext , event :T . MachineEvent ) :any => {
48
48
// TODO calculate from progress
49
49
50
50
const { position} = context
@@ -62,7 +62,7 @@ const contextActions: ActionFunctionMap<CR.MachineContext, CR.MachineEvent> = {
62
62
63
63
const step :G . Step = steps [ stepIndex + 1 ]
64
64
65
- const nextPosition :CR . Position = {
65
+ const nextPosition :T . Position = {
66
66
...position ,
67
67
stepId :step . id ,
68
68
}
@@ -72,7 +72,7 @@ const contextActions: ActionFunctionMap<CR.MachineContext, CR.MachineEvent> = {
72
72
} ) ,
73
73
//@ts -ignore
74
74
updateLevelPosition :assign ( {
75
- position :( context :CR . MachineContext ) :CR . Position => {
75
+ position :( context :T . MachineContext ) :any => {
76
76
const { position} = context
77
77
const version = selectors . currentVersion ( context )
78
78
// merge in the updated position
@@ -82,7 +82,7 @@ const contextActions: ActionFunctionMap<CR.MachineContext, CR.MachineEvent> = {
82
82
const levelIndex = levels . findIndex ( ( l :G . Level ) => l . id === position . levelId )
83
83
const level :G . Level = levels [ levelIndex + 1 ]
84
84
85
- const nextPosition :CR . Position = {
85
+ const nextPosition :T . Position = {
86
86
levelId :level . id ,
87
87
stepId :level . steps [ 0 ] . id ,
88
88
}
@@ -92,7 +92,7 @@ const contextActions: ActionFunctionMap<CR.MachineContext, CR.MachineEvent> = {
92
92
} ) ,
93
93
//@ts -ignore
94
94
updateLevelProgress :assign ( {
95
- progress :( context :CR . MachineContext , event :CR . MachineEvent ) :CR . Progress => {
95
+ progress :( context :T . MachineContext , event :T . MachineEvent ) :any => {
96
96
// update progress by tracking completed
97
97
const { progress, position} = context
98
98
@@ -105,9 +105,9 @@ const contextActions: ActionFunctionMap<CR.MachineContext, CR.MachineEvent> = {
105
105
} ) ,
106
106
//@ts -ignore
107
107
updateStepProgress :assign ( {
108
- progress :( context :CR . MachineContext , event :CR . MachineEvent ) :CR . Progress => {
108
+ progress :( context :T . MachineContext , event :T . MachineEvent ) :any => {
109
109
// update progress by tracking completed
110
- const currentProgress :CR . Progress = context . progress
110
+ const currentProgress :T . Progress = context . progress
111
111
112
112
const { stepId} = event . payload
113
113
@@ -118,13 +118,13 @@ const contextActions: ActionFunctionMap<CR.MachineContext, CR.MachineEvent> = {
118
118
} ) ,
119
119
//@ts -ignore
120
120
updatePosition :assign ( {
121
- position :( context :CR . MachineContext , event :CR . MachineEvent ) :CR . Progress => {
121
+ position :( context :T . MachineContext , event :T . MachineEvent ) :any => {
122
122
const { position} = event . payload
123
123
return position
124
124
} ,
125
125
} ) ,
126
126
loadNext :send (
127
- ( context :CR . MachineContext ) :CR . Action => {
127
+ ( context :T . MachineContext ) :T . Action => {
128
128
const { position, progress} = context
129
129
130
130
const level = selectors . currentLevel ( context )
@@ -170,7 +170,7 @@ const contextActions: ActionFunctionMap<CR.MachineContext, CR.MachineEvent> = {
170
170
} ,
171
171
) ,
172
172
stepNext :send (
173
- ( context :CR . MachineContext ) :CR . Action => {
173
+ ( context :T . MachineContext ) :T . Action => {
174
174
const { position, progress} = context
175
175
176
176
const level :G . Level = selectors . currentLevel ( context )
@@ -203,19 +203,20 @@ const contextActions: ActionFunctionMap<CR.MachineContext, CR.MachineEvent> = {
203
203
tutorial ( ) {
204
204
return null
205
205
} ,
206
- progress ( ) :CR . Progress {
207
- const progress :CR . Progress = selectors . defaultProgress ( )
206
+ progress ( ) :T . Progress {
207
+ const progress :T . Progress = selectors . defaultProgress ( )
208
208
return progress
209
209
} ,
210
- position ( ) :CR . Position {
211
- const position :CR . Position = selectors . defaultPosition ( )
210
+ position ( ) :T . Position {
211
+ const position :T . Position = selectors . defaultPosition ( )
212
212
return position
213
213
} ,
214
214
} ) ,
215
215
//@ts -ignore
216
216
setError :assign ( {
217
- error :( context :CR . MachineContext , event :CR . MachineEvent ) :string | null => {
218
- return event . payload . error
217
+ error :( context :T . MachineContext , event :T . MachineEvent ) :any => {
218
+ const message :string | null = event . payload . error
219
+ return message
219
220
} ,
220
221
} ) ,
221
222
}