diff --git a/src/editor/commands/index.ts b/src/editor/commands/index.ts index 6cd66a59..aeaeba7a 100644 --- a/src/editor/commands/index.ts +++ b/src/editor/commands/index.ts @@ -63,6 +63,7 @@ export const createCommands = ({ context, machine, storage, git, position }: Cre const { steps } = tutorial.data const { setup } = steps[pos.stepId].actions await git.gitLoadCommits(setup) + machine.send('TUTORIAL_LOADED') }, [COMMANDS.TUTORIAL_SETUP]: async (tutorial: CR.Tutorial) => { console.log('tutorial setup', tutorial) diff --git a/src/state/actions/index.ts b/src/state/actions/index.ts index 9bdc9dce..1a3fd19b 100644 --- a/src/state/actions/index.ts +++ b/src/state/actions/index.ts @@ -32,6 +32,7 @@ export default { const canContinue = !!(tutorial && progress && hasGit && hasGitRemote) if (canContinue) { + // continue currentTutorial = tutorial currentProgress = progress } @@ -41,6 +42,7 @@ export default { async tutorialLaunch() { // TODO: add selection of tutorial id const tutorial: CR.Tutorial = await api({ resource: 'getTutorial', params: { id: '1' } }) + currentTutorial = tutorial console.log('api') console.log(tutorial) vscode.commands.executeCommand('coderoad.tutorial_launch', tutorial) @@ -49,6 +51,19 @@ export default { vscode.commands.executeCommand('coderoad.tutorial_setup', currentTutorial) vscode.commands.executeCommand('coderoad.open_webview', vscode.ViewColumn.Two) }, + initializeNewTutorial: assign({ + position: (context: any): CR.Position => { + const { data } = context + const levelId = data.summary.levelList[0] + const stageId = data.levels[levelId].stageList[0] + const stepId = data.stages[stageId].stepList[0] + return { + levelId, + stageId, + stepId + } + } + }), tutorialContinue: assign({ // load initial data, progress & position data(): CR.TutorialData { @@ -149,7 +164,22 @@ export default { return nextProgress } }), - stepLoadNext() { - console.log("LOAD NEXT STEP") + stepLoadNext: assign({ + position: (context: any) => { + const { data, position } = context + const { stepList } = data.stages[position.stageId] + const currentStepIndex = stepList.indexOf(position.stepId) + const nextStepId = stepList[currentStepIndex + 1] + return { + ...context.position, + stepId: nextStepId, + } + } + }), + loadLevel() { + console.log('loadLevel') + }, + loadStage() { + console.log('loadStage') } } \ No newline at end of file diff --git a/src/state/machine.ts b/src/state/machine.ts index 46921862..5071eff2 100644 --- a/src/state/machine.ts +++ b/src/state/machine.ts @@ -57,9 +57,15 @@ export const machine = Machine< }, Tutorial: { id: 'tutorial', - initial: 'Summary', + initial: 'Initialize', onEntry: ['tutorialSetup'], states: { + Initialize: { + onEntry: ['initializeNewTutorial'], + after: { + 0: 'Summary' + } + }, LoadNext: { id: 'tutorial-load-next', onEntry: ['tutorialLoadNext'], diff --git a/typings/index.d.ts b/typings/index.d.ts index b95db2cf..65f78019 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -146,6 +146,7 @@ export interface MachineStateSchema { } Tutorial: { states: { + Initialize: {} Summary: {} LoadNext: {} Level: {} diff --git a/web-app/src/containers/Tutorial/SummaryPage.tsx b/web-app/src/containers/Tutorial/SummaryPage.tsx index 8cbec9d8..9d3dffca 100644 --- a/web-app/src/containers/Tutorial/SummaryPage.tsx +++ b/web-app/src/containers/Tutorial/SummaryPage.tsx @@ -9,7 +9,7 @@ interface PageProps { const SummaryPage = (props: PageProps) => { const { data } = React.useContext(DataContext) - return props.send('LOAD_NEXT')} /> + return props.send('NEXT')} /> } export default SummaryPage