Skip to content

Fixes#7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/editor/commands/index.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -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)
Expand Down
34 changes: 32 additions & 2 deletions src/state/actions/index.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,6 +32,7 @@ export default {
const canContinue = !!(tutorial && progress && hasGit && hasGitRemote)

if (canContinue) {
// continue
currentTutorial = tutorial
currentProgress = progress
}
Expand All@@ -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)
Expand All@@ -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 {
Expand DownExpand Up@@ -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')
}
}
8 changes: 7 additions & 1 deletion src/state/machine.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -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'],
Expand Down
1 change: 1 addition & 0 deletions typings/index.d.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -146,6 +146,7 @@ export interface MachineStateSchema {
}
Tutorial: {
states: {
Initialize: {}
Summary: {}
LoadNext: {}
Level: {}
Expand Down
2 changes: 1 addition & 1 deletion web-app/src/containers/Tutorial/SummaryPage.tsx
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,7 +9,7 @@ interface PageProps {

const SummaryPage = (props: PageProps) => {
const { data } = React.useContext(DataContext)
return <Summary data={data} onNext={() => props.send('LOAD_NEXT')} />
return <Summary data={data} onNext={() => props.send('NEXT')} />
}

export default SummaryPage
close