@@ -9,7 +9,8 @@ interface TutorialConfig {
9
9
testRunner :G . EnumTestRunner
10
10
}
11
11
12
- interface PositionProgress {
12
+ interface MessageData {
13
+ tutorial ?:{ id :string }
13
14
position :CR . Position
14
15
progress :CR . Progress
15
16
}
@@ -20,12 +21,11 @@ export interface TutorialModel {
20
21
version :G . TutorialVersion
21
22
position :CR . Position
22
23
progress :CR . Progress
23
- init ( tutorial :G . Tutorial ) :void
24
- load ( tutorialId :string ) :void
24
+ launch ( tutorialId :string ) :void
25
25
level ( levelId ?:string ) :G . Level
26
26
stage ( stageId ?:string ) :G . Stage
27
27
step ( stepId ?:string ) :G . Step
28
- updateProgress ( ) :PositionProgress
28
+ updateProgress ( ) :void
29
29
nextPosition ( ) :CR . Position
30
30
hasExisting ( ) :Promise < boolean >
31
31
setClientDispatch ( editorDispatch :CR . EditorDispatch ) :void
@@ -37,11 +37,11 @@ class Tutorial implements TutorialModel {
37
37
public version :G . TutorialVersion
38
38
public position :CR . Position
39
39
public progress :CR . Progress
40
- private clientDispatch :( props :PositionProgress ) => void
40
+ private clientDispatch :( props :MessageData ) => void
41
41
42
42
constructor ( ) {
43
43
// initialize types, will be assigned when tutorial is selected
44
- this . clientDispatch = ( props :PositionProgress ) => {
44
+ this . clientDispatch = ( props :MessageData ) => {
45
45
throw new Error ( 'Tutorial client dispatch yet initialized' )
46
46
}
47
47
this . repo = { } as G . TutorialRepo
@@ -62,10 +62,18 @@ class Tutorial implements TutorialModel {
62
62
}
63
63
64
64
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} )
66
66
}
67
67
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
+
69
77
this . repo = tutorial . repo
70
78
this . config = {
71
79
codingLanguage :tutorial . codingLanguage ,
@@ -90,6 +98,7 @@ class Tutorial implements TutorialModel {
90
98
console . log ( 'this.position' , JSON . stringify ( this . position ) )
91
99
92
100
this . clientDispatch ( {
101
+ tutorial :{ id :tutorial . id } ,
93
102
position :this . position ,
94
103
progress :this . progress
95
104
} )
@@ -111,19 +120,6 @@ class Tutorial implements TutorialModel {
111
120
112
121
return ! ! ( tutorial && progress )
113
122
}
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
- }
127
123
public level = ( levelId :string ) :G . Level => {
128
124
const level :G . Level | undefined = this . version . levels . find ( ( l :G . Level ) => l . id === levelId || this . position . levelId )
129
125
if ( ! level ) {
@@ -147,15 +143,16 @@ class Tutorial implements TutorialModel {
147
143
}
148
144
return step
149
145
}
150
- public updateProgress = ( ) : { position : CR . Position , progress : CR . Progress } => {
146
+ public updateProgress = ( ) => {
151
147
const { levelId, stageId, stepId} = this . position
152
148
this . progress . levels [ levelId ] = true
153
149
this . progress . stages [ stageId ] = true
154
150
this . progress . steps [ stepId ] = true
155
- return {
156
- position : this . position ,
151
+
152
+ this . clientDispatch ( {
157
153
progress :this . progress ,
158
- }
154
+ position :this . position , // TODO: calculate next position
155
+ } )
159
156
}
160
157
public nextPosition = ( ) :CR . Position => {
161
158
const { levelId, stageId, stepId} = this . position