@@ -3,6 +3,7 @@ import * as TT from 'typings/tutorial'
33import { assign , send , ActionFunctionMap } from 'xstate'
44import * as selectors from '../../selectors'
55import onError from '../../../services/sentry/onError'
6+ import logger from '../../../services/logger'
67
78const contextActions : ActionFunctionMap < T . MachineContext , T . MachineEvent > = {
89 // @ts -ignore
@@ -15,25 +16,20 @@ const contextActions: ActionFunctionMap<T.MachineContext, T.MachineEvent> = {
1516 } ,
1617 } ) ,
1718 // @ts -ignore
18- storeContinuedTutorial : assign ( {
19- env : ( context : T . MachineContext , event : T . MachineEvent ) => {
20- return {
19+ loadContinuedTutorial : assign ( ( context : T . MachineContext , event : T . MachineEvent ) : any => {
20+ return {
21+ env : {
2122 ...context . env ,
2223 ...event . payload . env ,
23- }
24- } ,
25- tutorial : ( context : T . MachineContext , event : T . MachineEvent ) => {
26- return event . payload . tutorial
27- } ,
28- progress : ( context : T . MachineContext , event : T . MachineEvent ) => {
29- return event . payload . progress
30- } ,
31- position : ( context : T . MachineContext , event : T . MachineEvent ) => {
32- return event . payload . position
33- } ,
24+ } ,
25+ tutorial : event . payload . tutorial ,
26+ progress : event . payload . progress ,
27+ position : event . payload . position ,
28+ }
3429 } ) ,
30+
3531 // @ts -ignore
36- startNewTutorial : assign ( {
32+ initProgressPosition : assign ( {
3733 position : ( context : T . MachineContext , event : T . MachineEvent ) : any => {
3834 const position : T . Position = selectors . initialPosition ( context )
3935 return position
@@ -119,8 +115,7 @@ const contextActions: ActionFunctionMap<T.MachineContext, T.MachineEvent> = {
119115 // @ts -ignore
120116 updatePosition : assign ( {
121117 position : ( context : T . MachineContext , event : T . MachineEvent ) : any => {
122- const { position } = event . payload
123- return position
118+ return event . payload
124119 } ,
125120 } ) ,
126121 loadNext : send (
@@ -140,7 +135,7 @@ const contextActions: ActionFunctionMap<T.MachineContext, T.MachineEvent> = {
140135 // NEXT STEP
141136 if ( hasNextStep ) {
142137 const nextPosition = { ...position , stepId : steps [ stepIndex + 1 ] . id }
143- return { type : 'NEXT_STEP' , payload : { position : nextPosition } }
138+ return { type : 'NEXT_STEP' , payload : nextPosition }
144139 }
145140
146141 // has next level?
@@ -164,7 +159,7 @@ const contextActions: ActionFunctionMap<T.MachineContext, T.MachineEvent> = {
164159 levelId : nextLevel . id ,
165160 stepId : nextLevel . steps [ 0 ] . id ,
166161 }
167- return { type : 'NEXT_LEVEL' , payload : { position : nextPosition } }
162+ return { type : 'NEXT_LEVEL' , payload : nextPosition }
168163 }
169164
170165 // COMPLETED
@@ -230,8 +225,9 @@ const contextActions: ActionFunctionMap<T.MachineContext, T.MachineEvent> = {
230225 error : ( ) : any => null ,
231226 } ) ,
232227 // @ts -ignore
233- checkEmptySteps : send ( ( context : T . MachineContext ) => {
228+ checkLevelCompleted : send ( ( context : T . MachineContext ) => {
234229 // no step id indicates no steps to complete
230+ logger ( context . position )
235231 return {
236232 type : context . position . stepId === null ? 'START_COMPLETED_LEVEL' : 'START_LEVEL' ,
237233 }
0 commit comments