Skip to content

Commit a12f254

Browse files
authored
Merge pull request #7 from ShMcK/fixes
Fixes
2 parents 9509a15 + 5d0abd6 commit a12f254

File tree

5 files changed

+42
-4
lines changed

5 files changed

+42
-4
lines changed

src/editor/commands/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export const createCommands = ({ context, machine, storage, git, position }: Cre
6363
const{ steps }=tutorial.data
6464
const{ setup }=steps[pos.stepId].actions
6565
awaitgit.gitLoadCommits(setup)
66+
machine.send('TUTORIAL_LOADED')
6667
},
6768
[COMMANDS.TUTORIAL_SETUP]: async(tutorial: CR.Tutorial)=>{
6869
console.log('tutorial setup',tutorial)

src/state/actions/index.ts

+32-2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export default {
3232
constcanContinue=!!(tutorial&&progress&&hasGit&&hasGitRemote)
3333

3434
if(canContinue){
35+
// continue
3536
currentTutorial=tutorial
3637
currentProgress=progress
3738
}
@@ -41,6 +42,7 @@ export default {
4142
asynctutorialLaunch(){
4243
// TODO: add selection of tutorial id
4344
consttutorial: CR.Tutorial=awaitapi({resource: 'getTutorial',params: {id: '1'}})
45+
currentTutorial=tutorial
4446
console.log('api')
4547
console.log(tutorial)
4648
vscode.commands.executeCommand('coderoad.tutorial_launch',tutorial)
@@ -49,6 +51,19 @@ export default {
4951
vscode.commands.executeCommand('coderoad.tutorial_setup',currentTutorial)
5052
vscode.commands.executeCommand('coderoad.open_webview',vscode.ViewColumn.Two)
5153
},
54+
initializeNewTutorial: assign({
55+
position: (context: any): CR.Position=>{
56+
const{ data }=context
57+
constlevelId=data.summary.levelList[0]
58+
conststageId=data.levels[levelId].stageList[0]
59+
conststepId=data.stages[stageId].stepList[0]
60+
return{
61+
levelId,
62+
stageId,
63+
stepId
64+
}
65+
}
66+
}),
5267
tutorialContinue: assign({
5368
// load initial data, progress & position
5469
data(): CR.TutorialData{
@@ -149,7 +164,22 @@ export default {
149164
returnnextProgress
150165
}
151166
}),
152-
stepLoadNext(){
153-
console.log("LOAD NEXT STEP")
167+
stepLoadNext: assign({
168+
position: (context: any)=>{
169+
const{ data, position }=context
170+
const{ stepList }=data.stages[position.stageId]
171+
constcurrentStepIndex=stepList.indexOf(position.stepId)
172+
constnextStepId=stepList[currentStepIndex+1]
173+
return{
174+
...context.position,
175+
stepId: nextStepId,
176+
}
177+
}
178+
}),
179+
loadLevel(){
180+
console.log('loadLevel')
181+
},
182+
loadStage(){
183+
console.log('loadStage')
154184
}
155185
}

src/state/machine.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,15 @@ export const machine = Machine<
5757
},
5858
Tutorial: {
5959
id: 'tutorial',
60-
initial: 'Summary',
60+
initial: 'Initialize',
6161
onEntry: ['tutorialSetup'],
6262
states: {
63+
Initialize: {
64+
onEntry: ['initializeNewTutorial'],
65+
after: {
66+
0: 'Summary'
67+
}
68+
},
6369
LoadNext: {
6470
id: 'tutorial-load-next',
6571
onEntry: ['tutorialLoadNext'],

typings/index.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ export interface MachineStateSchema {
146146
}
147147
Tutorial: {
148148
states: {
149+
Initialize: {}
149150
Summary: {}
150151
LoadNext: {}
151152
Level: {}

web-app/src/containers/Tutorial/SummaryPage.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ interface PageProps {
99

1010
constSummaryPage=(props: PageProps)=>{
1111
const{ data }=React.useContext(DataContext)
12-
return<Summarydata={data}onNext={()=>props.send('LOAD_NEXT')}/>
12+
return<Summarydata={data}onNext={()=>props.send('NEXT')}/>
1313
}
1414

1515
exportdefaultSummaryPage

0 commit comments

Comments
 (0)
close