@@ -9,7 +9,8 @@ interface TutorialConfig {
99 testRunner : G . EnumTestRunner
1010}
1111
12- interface PositionProgress {
12+ interface MessageData {
13+ tutorial ?: { id : string }
1314 position : CR . Position
1415 progress : CR . Progress
1516}
@@ -20,12 +21,11 @@ export interface TutorialModel {
2021 version : G . TutorialVersion
2122 position : CR . Position
2223 progress : CR . Progress
23- init ( tutorial : G . Tutorial ) : void
24- load ( tutorialId : string ) : void
24+ launch ( tutorialId : string ) : void
2525 level ( levelId ?: string ) : G . Level
2626 stage ( stageId ?: string ) : G . Stage
2727 step ( stepId ?: string ) : G . Step
28- updateProgress ( ) : PositionProgress
28+ updateProgress ( ) : void
2929 nextPosition ( ) : CR . Position
3030 hasExisting ( ) : Promise < boolean >
3131 setClientDispatch ( editorDispatch : CR . EditorDispatch ) : void
@@ -37,11 +37,11 @@ class Tutorial implements TutorialModel {
3737 public version : G . TutorialVersion
3838 public position : CR . Position
3939 public progress : CR . Progress
40- private clientDispatch : ( props : PositionProgress ) => void
40+ private clientDispatch : ( props : MessageData ) => void
4141
4242 constructor ( ) {
4343 // initialize types, will be assigned when tutorial is selected
44- this . clientDispatch = ( props : PositionProgress ) => {
44+ this . clientDispatch = ( props : MessageData ) => {
4545 throw new Error ( 'Tutorial client dispatch yet initialized' )
4646 }
4747 this . repo = { } as G . TutorialRepo
@@ -62,10 +62,18 @@ class Tutorial implements TutorialModel {
6262 }
6363
6464 public setClientDispatch ( editorDispatch : CR . EditorDispatch ) {
65- this . clientDispatch = ( { progress, position} : PositionProgress ) => editorDispatch ( 'coderoad.send_data' , { progress, position} )
65+ this . clientDispatch = ( { progress, position} : MessageData ) => editorDispatch ( 'coderoad.send_data' , { progress, position} )
6666 }
6767
68- public init = ( tutorial : G . Tutorial ) => {
68+ public async launch ( tutorialId : string ) {
69+ const { tutorial} : { tutorial : G . Tutorial | null } = await api . request ( tutorialQuery , {
70+ tutorialId, // TODO: add selection of tutorial id
71+ } )
72+
73+ if ( ! tutorial ) {
74+ throw new Error ( `Tutorial ${ tutorialId } not found` )
75+ }
76+
6977 this . repo = tutorial . repo
7078 this . config = {
7179 codingLanguage : tutorial . codingLanguage ,
@@ -90,6 +98,7 @@ class Tutorial implements TutorialModel {
9098 console . log ( 'this.position' , JSON . stringify ( this . position ) )
9199
92100 this . clientDispatch ( {
101+ tutorial : { id : tutorial . id } ,
93102 position : this . position ,
94103 progress : this . progress
95104 } )
@@ -111,19 +120,6 @@ class Tutorial implements TutorialModel {
111120
112121 return ! ! ( tutorial && progress )
113122 }
114-
115- public async load ( tutorialId : string ) {
116- // TODO: load from localStorage
117- const { tutorial} : { tutorial : G . Tutorial | null } = await api . request ( tutorialQuery , {
118- tutorialId, // TODO: add selection of tutorial id
119- } )
120-
121- if ( ! tutorial ) {
122- throw new Error ( `Tutorial ${ tutorialId } not found` )
123- }
124-
125- await this . init ( tutorial )
126- }
127123 public level = ( levelId : string ) : G . Level => {
128124 const level : G . Level | undefined = this . version . levels . find ( ( l : G . Level ) => l . id === levelId || this . position . levelId )
129125 if ( ! level ) {
@@ -147,15 +143,16 @@ class Tutorial implements TutorialModel {
147143 }
148144 return step
149145 }
150- public updateProgress = ( ) : { position : CR . Position , progress : CR . Progress } => {
146+ public updateProgress = ( ) => {
151147 const { levelId, stageId, stepId} = this . position
152148 this . progress . levels [ levelId ] = true
153149 this . progress . stages [ stageId ] = true
154150 this . progress . steps [ stepId ] = true
155- return {
156- position : this . position ,
151+
152+ this . clientDispatch ( {
157153 progress : this . progress ,
158- }
154+ position : this . position , // TODO: calculate next position
155+ } )
159156 }
160157 public nextPosition = ( ) : CR . Position => {
161158 const { levelId, stageId, stepId} = this . position
0 commit comments