@@ -9,7 +9,8 @@ interface TutorialConfig {
99testRunner :G . EnumTestRunner
1010}
1111
12- interface PositionProgress {
12+ interface MessageData {
13+ tutorial ?:{ id :string }
1314position :CR . Position
1415progress :CR . Progress
1516}
@@ -20,12 +21,11 @@ export interface TutorialModel {
2021version :G . TutorialVersion
2122position :CR . Position
2223progress :CR . Progress
23- init ( tutorial :G . Tutorial ) :void
24- load ( tutorialId :string ) :void
24+ launch ( tutorialId :string ) :void
2525level ( levelId ?:string ) :G . Level
2626stage ( stageId ?:string ) :G . Stage
2727step ( stepId ?:string ) :G . Step
28- updateProgress ( ) :PositionProgress
28+ updateProgress ( ) :void
2929nextPosition ( ) :CR . Position
3030hasExisting ( ) :Promise < boolean >
3131setClientDispatch ( editorDispatch :CR . EditorDispatch ) :void
@@ -37,11 +37,11 @@ class Tutorial implements TutorialModel {
3737public version :G . TutorialVersion
3838public position :CR . Position
3939public progress :CR . Progress
40- private clientDispatch :( props :PositionProgress ) => void
40+ private clientDispatch :( props :MessageData ) => void
4141
4242constructor ( ) {
4343// initialize types, will be assigned when tutorial is selected
44- this . clientDispatch = ( props :PositionProgress ) => {
44+ this . clientDispatch = ( props :MessageData ) => {
4545throw new Error ( 'Tutorial client dispatch yet initialized' )
4646}
4747this . repo = { } as G . TutorialRepo
@@ -62,10 +62,18 @@ class Tutorial implements TutorialModel {
6262}
6363
6464public 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+
6977this . repo = tutorial . repo
7078this . config = {
7179codingLanguage :tutorial . codingLanguage ,
@@ -90,6 +98,7 @@ class Tutorial implements TutorialModel {
9098console . log ( 'this.position' , JSON . stringify ( this . position ) )
9199
92100this . clientDispatch ( {
101+ tutorial :{ id :tutorial . id } ,
93102position :this . position ,
94103progress :this . progress
95104} )
@@ -111,19 +120,6 @@ class Tutorial implements TutorialModel {
111120
112121return ! ! ( 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- }
127123public level = ( levelId :string ) :G . Level => {
128124const level :G . Level | undefined = this . version . levels . find ( ( l :G . Level ) => l . id === levelId || this . position . levelId )
129125if ( ! level ) {
@@ -147,15 +143,16 @@ class Tutorial implements TutorialModel {
147143}
148144return step
149145}
150- public updateProgress = ( ) : { position : CR . Position , progress : CR . Progress } => {
146+ public updateProgress = ( ) => {
151147const { levelId, stageId, stepId} = this . position
152148this . progress . levels [ levelId ] = true
153149this . progress . stages [ stageId ] = true
154150this . progress . steps [ stepId ] = true
155- return {
156- position : this . position ,
151+
152+ this . clientDispatch ( {
157153progress :this . progress ,
158- }
154+ position :this . position , // TODO: calculate next position
155+ } )
159156}
160157public nextPosition = ( ) :CR . Position => {
161158const { levelId, stageId, stepId} = this . position