1- import * as CR from 'typings'
1+ import * as T from 'typings'
22import * as G from 'typings/graphql'
33import { assign , send , ActionFunctionMap } from 'xstate'
44import * as selectors from '../../selectors'
55import onError from '../../../services/sentry/onError'
66
7- const contextActions :ActionFunctionMap < CR . MachineContext , CR . MachineEvent > = {
7+ const contextActions :ActionFunctionMap < T . MachineContext , T . MachineEvent > = {
88//@ts -ignore
99setEnv :assign ( {
10- env :( context :CR . MachineContext , event :CR . MachineEvent ) => {
10+ env :( context :T . MachineContext , event :T . MachineEvent ) => {
1111return {
1212 ...context . env ,
1313 ...event . payload . env ,
@@ -16,35 +16,35 @@ const contextActions: ActionFunctionMap<CR.MachineContext, CR.MachineEvent> = {
1616} ) ,
1717//@ts -ignore
1818continueTutorial :assign ( {
19- tutorial :( context :CR . MachineContext , event :CR . MachineEvent ) => {
19+ tutorial :( context :T . MachineContext , event :T . MachineEvent ) => {
2020return event . payload . tutorial
2121} ,
22- progress :( context :CR . MachineContext , event :CR . MachineEvent ) => {
22+ progress :( context :T . MachineContext , event :T . MachineEvent ) => {
2323return event . payload . progress
2424} ,
25- position :( context :CR . MachineContext , event :CR . MachineEvent ) => {
25+ position :( context :T . MachineContext , event :T . MachineEvent ) => {
2626return event . payload . position
2727} ,
2828} ) ,
2929//@ts -ignore
3030selectTutorialById :assign ( {
31- tutorial :( context :CR . MachineContext , event :CR . MachineEvent ) :any => {
31+ tutorial :( context :T . MachineContext , event :T . MachineEvent ) :any => {
3232return event . payload . tutorial
3333} ,
3434} ) ,
3535//@ts -ignore
3636startNewTutorial :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 )
3939return position
4040} ,
41- progress :( ) :CR . Progress => {
41+ progress :( ) :T . Progress => {
4242return { levels :{ } , steps :{ } , complete :false }
4343} ,
4444} ) ,
4545//@ts -ignore
4646updateStepPosition :assign ( {
47- position :( context :CR . MachineContext , event :CR . MachineEvent ) :CR . Position => {
47+ position :( context :T . MachineContext , event :T . MachineEvent ) :any => {
4848// TODO calculate from progress
4949
5050const { position} = context
@@ -62,7 +62,7 @@ const contextActions: ActionFunctionMap<CR.MachineContext, CR.MachineEvent> = {
6262
6363const step :G . Step = steps [ stepIndex + 1 ]
6464
65- const nextPosition :CR . Position = {
65+ const nextPosition :T . Position = {
6666 ...position ,
6767stepId :step . id ,
6868}
@@ -72,7 +72,7 @@ const contextActions: ActionFunctionMap<CR.MachineContext, CR.MachineEvent> = {
7272} ) ,
7373//@ts -ignore
7474updateLevelPosition :assign ( {
75- position :( context :CR . MachineContext ) :CR . Position => {
75+ position :( context :T . MachineContext ) :any => {
7676const { position} = context
7777const version = selectors . currentVersion ( context )
7878// merge in the updated position
@@ -82,7 +82,7 @@ const contextActions: ActionFunctionMap<CR.MachineContext, CR.MachineEvent> = {
8282const levelIndex = levels . findIndex ( ( l :G . Level ) => l . id === position . levelId )
8383const level :G . Level = levels [ levelIndex + 1 ]
8484
85- const nextPosition :CR . Position = {
85+ const nextPosition :T . Position = {
8686levelId :level . id ,
8787stepId :level . steps [ 0 ] . id ,
8888}
@@ -92,7 +92,7 @@ const contextActions: ActionFunctionMap<CR.MachineContext, CR.MachineEvent> = {
9292} ) ,
9393//@ts -ignore
9494updateLevelProgress :assign ( {
95- progress :( context :CR . MachineContext , event :CR . MachineEvent ) :CR . Progress => {
95+ progress :( context :T . MachineContext , event :T . MachineEvent ) :any => {
9696// update progress by tracking completed
9797const { progress, position} = context
9898
@@ -105,9 +105,9 @@ const contextActions: ActionFunctionMap<CR.MachineContext, CR.MachineEvent> = {
105105} ) ,
106106//@ts -ignore
107107updateStepProgress :assign ( {
108- progress :( context :CR . MachineContext , event :CR . MachineEvent ) :CR . Progress => {
108+ progress :( context :T . MachineContext , event :T . MachineEvent ) :any => {
109109// update progress by tracking completed
110- const currentProgress :CR . Progress = context . progress
110+ const currentProgress :T . Progress = context . progress
111111
112112const { stepId} = event . payload
113113
@@ -118,13 +118,13 @@ const contextActions: ActionFunctionMap<CR.MachineContext, CR.MachineEvent> = {
118118} ) ,
119119//@ts -ignore
120120updatePosition :assign ( {
121- position :( context :CR . MachineContext , event :CR . MachineEvent ) :CR . Progress => {
121+ position :( context :T . MachineContext , event :T . MachineEvent ) :any => {
122122const { position} = event . payload
123123return position
124124} ,
125125} ) ,
126126loadNext :send (
127- ( context :CR . MachineContext ) :CR . Action => {
127+ ( context :T . MachineContext ) :T . Action => {
128128const { position, progress} = context
129129
130130const level = selectors . currentLevel ( context )
@@ -170,7 +170,7 @@ const contextActions: ActionFunctionMap<CR.MachineContext, CR.MachineEvent> = {
170170} ,
171171) ,
172172stepNext :send (
173- ( context :CR . MachineContext ) :CR . Action => {
173+ ( context :T . MachineContext ) :T . Action => {
174174const { position, progress} = context
175175
176176const level :G . Level = selectors . currentLevel ( context )
@@ -203,19 +203,20 @@ const contextActions: ActionFunctionMap<CR.MachineContext, CR.MachineEvent> = {
203203tutorial ( ) {
204204return null
205205} ,
206- progress ( ) :CR . Progress {
207- const progress :CR . Progress = selectors . defaultProgress ( )
206+ progress ( ) :T . Progress {
207+ const progress :T . Progress = selectors . defaultProgress ( )
208208return progress
209209} ,
210- position ( ) :CR . Position {
211- const position :CR . Position = selectors . defaultPosition ( )
210+ position ( ) :T . Position {
211+ const position :T . Position = selectors . defaultPosition ( )
212212return position
213213} ,
214214} ) ,
215215//@ts -ignore
216216setError :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
219220} ,
220221} ) ,
221222}