Skip to content

Commit f174afa

Browse files
committed
load progress on server and send to client
1 parent 0f992bf commit f174afa

File tree

4 files changed

+18
-70
lines changed

4 files changed

+18
-70
lines changed

typings/index.d.ts

-5
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,3 @@ interface MessageState {
181181

182182
// todo: type each string param and payload
183183
export type EditorDispatch = (type: string, payload?: MessageData | MessageState | any) => void
184-
185-
export interface EditorStorage {
186-
currentTutorial: Storage<{id: string | null, version: string | null}>
187-
stepProgress: Storage<StepProgress>
188-
}

web-app/src/services/state/actions/context.ts

+13-54
Original file line numberDiff line numberDiff line change
@@ -4,60 +4,17 @@ import * as CR from 'typings'
44
import * as selectors from '../../selectors'
55

66
export default {
7-
continueTutorial: (context: CR.MachineContext, event: CR.MachineEvent) => {
8-
9-
const {tutorial, stepProgress} = event.payload
10-
// NOTE: tutorial does not contain levels/stages/steps etc.
11-
12-
const progress: CR.Progress = {
13-
steps: stepProgress,
14-
stages: {},
15-
levels: {},
16-
complete: false
17-
}
18-
19-
const position: CR.Position = {
20-
stepId: '',
21-
stageId: '',
22-
levelId: '',
23-
}
24-
25-
// calculate progress from tutorial & stepProgress
26-
for (const level of tutorial.version.levels) {
27-
for (const stage of level.stages) {
28-
// set stage progress
29-
const stageComplete: boolean = stage.steps.every((step: G.Step) => {
30-
return stepProgress[step.id]
31-
})
32-
if (stageComplete) {
33-
progress.stages[stage.id] = true
34-
} else if (!position.stageId.length) {
35-
// set stage amd step position
36-
position.stageId = stage.id
37-
position.stepId = stage.steps.find((step: G.Step) => !stepProgress[step.id]).id
38-
}
39-
}
40-
// set level progress
41-
const levelComplete: boolean = level.stages.every((stage: G.Stage) => {
42-
return progress.stages[stage.id]
43-
})
44-
if (levelComplete) {
45-
progress.levels[level.id] = true
46-
} else if (!position.levelId.length) {
47-
position.levelId = level.id
48-
}
49-
}
50-
// set tutorial progress
51-
progress.complete = tutorial.version.levels.every((level: G.Level) => {
52-
return progress.levels[level.id]
53-
})
54-
55-
return assign({
56-
tutorial,
57-
progress,
58-
position,
59-
})
60-
},
7+
continueTutorial: assign({
8+
tutorial: (context: CR.MachineContext, event: CR.MachineEvent) => {
9+
return event.payload.tutorial
10+
},
11+
progress: (context: CR.MachineContext, event: CR.MachineEvent) => {
12+
return event.payload.progress
13+
},
14+
position: (context: CR.MachineContext, event: CR.MachineEvent) => {
15+
return event.payload.position
16+
},
17+
}),
6118
setTutorial: assign({
6219
tutorial: (context: CR.MachineContext, event: CR.MachineEvent): any => {
6320
const {tutorial} = event.payload
@@ -144,6 +101,8 @@ export default {
144101
// @ts-ignore
145102
updateStepProgress: assign({
146103
progress: (context: CR.MachineContext, event: CR.MachineEvent): CR.Progress => {
104+
console.log('updateStepProgress')
105+
console.log(JSON.stringify(event))
147106
// update progress by tracking completed
148107
const currentProgress: CR.Progress = context.progress
149108

web-app/src/services/state/actions/editor.ts

+4-11
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import channel from '../../channel'
66
export default {
77
loadStoredTutorial() {
88
channel.editorSend({
9-
type: 'TUTORIAL_LOAD_STORED',
9+
type: 'EDITOR_TUTORIAL_LOAD',
1010
})
1111
},
1212
initializeTutorial(context: CR.MachineContext, event: CR.MachineEvent) {
@@ -15,17 +15,10 @@ export default {
1515
if (!tutorial) {
1616
throw new Error('Invalid tutorial for tutorial config')
1717
}
18-
const payload = {
19-
id: tutorial.id,
20-
version: tutorial.version.version,
21-
codingLanguage: tutorial.codingLanguage,
22-
testRunner: tutorial.testRunner,
23-
repo: tutorial.repo,
24-
}
25-
console.log('EDITOR: TUTORIAL_CONFIG', payload)
18+
console.log('EDITOR: TUTORIAL_CONFIG', tutorial)
2619
channel.editorSend({
27-
type: 'TUTORIAL_CONFIG',
28-
payload,
20+
type: 'EDITOR_TUTORIAL_CONFIG',
21+
payload: {tutorial},
2922
})
3023
},
3124
testStart(context: CR.MachineContext, event: CR.MachineEvent) {

web-app/src/services/state/actions/invoke.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import client from '../../apollo'
33
import tutorialQuery from '../../apollo/queries/tutorial'
44

55
export const loadTutorial = async (context: CR.MachineContext) => {
6+
67
if (!context.tutorial) {
78
throw new Error('Tutorial not available to load')
89
}

0 commit comments

Comments
 (0)