@@ -14,6 +14,24 @@ let currentProgress: CR.Progress = {
1414complete :false ,
1515}
1616
17+ const calculatePosition = ( { data, progress} :{ data :CR . TutorialData , progress :CR . Progress } ) :CR . Position => {
18+ const { levelList} = data . summary
19+ // take next incomplete level or the final step
20+ const levelId = levelList . find ( ( id :string ) => ! progress . levels [ id ] ) || levelList [ levelList . length - 1 ]
21+ const { stageList} = data . levels [ levelId ]
22+ const stageId = stageList . find ( ( id :string ) => ! progress . stages [ id ] ) || stageList [ stageList . length - 1 ]
23+ const { stepList} = data . stages [ stageId ]
24+ const stepId = stepList . find ( ( id :string ) => ! progress . steps [ id ] ) || stepList [ stepList . length - 1 ]
25+
26+ const nextPosition :CR . Position = {
27+ levelId,
28+ stageId,
29+ stepId,
30+ }
31+
32+ return nextPosition
33+ }
34+
1735export default ( dispatch :CR . EditorDispatch ) => ( {
1836createWebview ( ) {
1937dispatch ( 'coderoad.open_webview' )
@@ -79,24 +97,9 @@ export default (dispatch: CR.EditorDispatch) => ({
7997if ( ! currentTutorial ) {
8098throw new Error ( 'No Tutorial loaded' )
8199}
82-
83100const { data} = currentTutorial
101+ const position = calculatePosition ( { data, progress :currentProgress } )
84102
85- const { levelList} = data . summary
86- // take next incomplete level or the final step
87- const levelId = levelList . find ( ( id :string ) => ! currentProgress . levels [ id ] ) || levelList [ levelList . length - 1 ]
88- const { stageList} = data . levels [ levelId ]
89- const stageId = stageList . find ( ( id :string ) => ! currentProgress . stages [ id ] ) || stageList [ stageList . length - 1 ]
90- console . log ( 'position stepList' )
91- console . log ( data . stages [ stageId ] )
92- const { stepList} = data . stages [ stageId ]
93- const stepId = stepList . find ( ( id :string ) => ! currentProgress . steps [ id ] ) || stepList [ stepList . length - 1 ]
94-
95- const position = {
96- levelId,
97- stageId,
98- stepId,
99- }
100103console . log ( 'position' , position )
101104return position
102105} ,
@@ -113,6 +116,7 @@ export default (dispatch: CR.EditorDispatch) => ({
113116//@ts -ignore
114117progressUpdate :assign ( {
115118progress :( context :CR . MachineContext ) :CR . Progress => {
119+ console . log ( 'progress update' )
116120const { progress, position, data} = context
117121const nextProgress = progress
118122
@@ -156,9 +160,23 @@ export default (dispatch: CR.EditorDispatch) => ({
156160loadLevel ( ) {
157161console . log ( 'loadLevel' )
158162} ,
159- loadStage ( ) {
163+ stageLoadNext ( context :CR . MachineContext ) {
164+ console . log ( 'stageLoadNext' )
165+ const { position} = context
166+ console . log ( position )
167+ } ,
168+ loadStage ( context :CR . MachineContext ) :void {
160169console . log ( 'loadStage' )
170+ const { position} = context
171+ console . log ( position )
161172} ,
173+ //@ts -ignore
174+ updatePosition :assign ( {
175+ position :( context :CR . MachineContext ) => calculatePosition ( {
176+ data :context . data ,
177+ progress :context . progress ,
178+ } ) ,
179+ } ) ,
162180stepLoadCommits ( context :CR . MachineContext ) :void {
163181const { data, position} = context
164182const { setup} = data . steps [ position . stepId ] . actions