11import { assign } from 'xstate'
22import * as G from 'typings/graphql'
33import * as CR from 'typings'
4+ import * as storage from './storage'
45
56export default {
67 setTutorial : assign ( {
78 tutorial : ( context : CR . MachineContext , event : CR . MachineEvent ) : any => {
8- return event . payload . tutorial
9+ const { tutorial} = event . payload
10+ storage . tutorial . set ( tutorial )
11+ return tutorial
912 } ,
1013 } ) ,
1114 // @ts -ignore
@@ -23,6 +26,8 @@ export default {
2326 stepId : version . levels [ 0 ] . stages [ 0 ] . steps [ 0 ] . id ,
2427 }
2528
29+ storage . position . set ( position )
30+
2631 return position
2732 } ,
2833 } ) ,
@@ -42,10 +47,14 @@ export default {
4247
4348 console . log ( 'step load next' , step . id , position . stepId )
4449
45- return {
50+ const nextPosition : CR . Position = {
4651 ...position ,
4752 stepId : step . id
4853 }
54+
55+ storage . position . set ( nextPosition )
56+
57+ return nextPosition
4958 } ,
5059 } ) ,
5160 // @ts -ignore
@@ -63,11 +72,15 @@ export default {
6372
6473 console . log ( 'stage load next' , stage . id , position . stageId )
6574
66- return {
75+ const nextPosition : CR . Position = {
6776 ...position ,
6877 stageId : stage . id ,
6978 stepId : stage . steps [ 0 ] . id ,
7079 }
80+
81+ storage . position . set ( nextPosition )
82+
83+ return nextPosition
7184 } ,
7285 } ) ,
7386 // @ts -ignore
@@ -83,11 +96,15 @@ export default {
8396
8497 console . log ( 'level load next' , level . id , position . levelId )
8598
86- return {
99+ const nextPosition : CR . Position = {
87100 levelId : level . id ,
88101 stageId : level . stages [ 0 ] . id ,
89102 stepId : level . stages [ 0 ] . steps [ 0 ] . id ,
90103 }
104+
105+ storage . position . set ( nextPosition )
106+
107+ return nextPosition
91108 } ,
92109 } ) ,
93110 // @ts -ignore
@@ -100,6 +117,8 @@ export default {
100117
101118 currentProgress . steps [ stepId ] = true
102119
120+ storage . progress . set ( currentProgress )
121+
103122 return currentProgress
104123 } ,
105124 } ) ,
@@ -114,28 +133,35 @@ export default {
114133
115134 progress . stages [ stageId ] = true
116135
136+ storage . progress . set ( progress )
137+
117138 return progress
118139 } ,
119140 } ) ,
120141 // @ts -ignore
121142 reset : assign ( {
122143 tutorial ( ) {
144+ storage . tutorial . set ( null )
123145 return null
124146 } ,
125147 progress ( ) : CR . Progress {
126- return {
148+ const progress : CR . Progress = {
127149 levels : { } ,
128150 stages : { } ,
129151 steps : { } ,
130152 complete : false
131153 }
154+ storage . progress . set ( progress )
155+ return progress
132156 } ,
133157 position ( ) : CR . Position {
134- return {
158+ const position : CR . Position = {
135159 levelId : '' ,
136160 stageId : '' ,
137161 stepId : ''
138162 }
163+ storage . position . set ( position )
164+ return position
139165 }
140166 } )
141167}
0 commit comments