From 4feed762554dc3ba945219db05e62b374334e329 Mon Sep 17 00:00:00 2001 From: shmck Date: Thu, 13 Jun 2019 19:14:22 -0700 Subject: [PATCH 1/7] fix startup issue --- src/state/machine.ts | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/state/machine.ts b/src/state/machine.ts index 5071eff2..45c18283 100644 --- a/src/state/machine.ts +++ b/src/state/machine.ts @@ -20,8 +20,8 @@ export const machine = Machine< initial: 'Initial', states: { Initial: { - after: { - 2000: 'Startup' + on: { + WEBVIEW_INITIALIZED: 'Startup' } }, Startup: { @@ -50,7 +50,7 @@ export const machine = Machine< ContinueTutorial: { onEntry: ['tutorialContinue'], on: { - TUTORIAL_START: '#tutorial-load-next' + TUTORIAL_START: '#tutorial-load-current' } }, } @@ -66,6 +66,13 @@ export const machine = Machine< 0: 'Summary' } }, + LoadCurrent: { + id: 'tutorial-load-current', + // TODO: verify current is not complete + after: { + 0: 'Stage' + }, + }, LoadNext: { id: 'tutorial-load-next', onEntry: ['tutorialLoadNext'], @@ -120,14 +127,9 @@ export const machine = Machine< TestPass: { onEntry: ['testPass', 'stepComplete'], after: { - 1000: { - target: 'StepNext', - cond: 'hasNextStep', - } - }, - on: { - NEXT: 'StageComplete', + 1000: 'StepNext', }, + }, TestFail: { onEntry: ['testFail'], @@ -138,8 +140,13 @@ export const machine = Machine< StepNext: { onEntry: ['stepLoadNext'], after: { - 0: 'Normal' - } + 0: [{ + target: 'Normal', + cond: 'hasNextStep', + }, { + target: 'StageComplete' + }] + }, }, StageComplete: { onEntry: 'stageComplete', From 7804d04977ea1d4ccd96cfe48f4a5e089153d2eb Mon Sep 17 00:00:00 2001 From: shmck Date: Thu, 13 Jun 2019 19:14:43 -0700 Subject: [PATCH 2/7] load current --- src/editor/ReactWebView.ts | 3 +-- src/editor/commands/index.ts | 3 +++ typings/index.d.ts | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/editor/ReactWebView.ts b/src/editor/ReactWebView.ts index de113d6b..95eca7a4 100644 --- a/src/editor/ReactWebView.ts +++ b/src/editor/ReactWebView.ts @@ -31,7 +31,7 @@ class ReactWebView { console.log('webview loaded') } - public async createOrShow(column: number): Promise { + public createOrShow(column: number): void { // If we already have a panel, show it. // Otherwise, create a new panel. if (this.panel && this.panel.webview) { @@ -40,7 +40,6 @@ class ReactWebView { } else { console.log('make new panel') this.panel = this.createWebviewPanel(column) - } } diff --git a/src/editor/commands/index.ts b/src/editor/commands/index.ts index aeaeba7a..c8f0067b 100644 --- a/src/editor/commands/index.ts +++ b/src/editor/commands/index.ts @@ -43,6 +43,9 @@ export const createCommands = ({ context, machine, storage, git, position }: Cre // open React webview [COMMANDS.OPEN_WEBVIEW]: (column: number = vscode.ViewColumn.One) => { webview.createOrShow(column); + setTimeout(() => { + machine.send('WEBVIEW_INITIALIZED') + }, 2000) }, // launch a new tutorial // NOTE: may be better to move into action as logic is primarily non-vscode diff --git a/typings/index.d.ts b/typings/index.d.ts index 65f78019..6100d36b 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -148,6 +148,7 @@ export interface MachineStateSchema { states: { Initialize: {} Summary: {} + LoadCurrent: {} LoadNext: {} Level: {} Stage: { From 23ab6b646751d4ea4fc27a70af15bf17c949b616 Mon Sep 17 00:00:00 2001 From: shmck Date: Thu, 13 Jun 2019 20:03:15 -0700 Subject: [PATCH 3/7] fix complete button toggle --- web-app/src/containers/Tutorial/StagePage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web-app/src/containers/Tutorial/StagePage.tsx b/web-app/src/containers/Tutorial/StagePage.tsx index 518afd3c..ed319137 100644 --- a/web-app/src/containers/Tutorial/StagePage.tsx +++ b/web-app/src/containers/Tutorial/StagePage.tsx @@ -25,7 +25,7 @@ const StagePage = (props: PageProps) => { ...data.steps[stepId], status: { // flag progressed steps as complete - complete: progress.steps[stepId] || false, + complete: progress.stages[stageId] || false, // set active step to active active: position.stepId === stepId, }, From b324bb3b5969bdbe7cb7f0668cfb9425ca36df72 Mon Sep 17 00:00:00 2001 From: shmck Date: Thu, 13 Jun 2019 20:03:21 -0700 Subject: [PATCH 4/7] add additional progress logging --- src/state/actions/index.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/state/actions/index.ts b/src/state/actions/index.ts index 1a3fd19b..7e13de90 100644 --- a/src/state/actions/index.ts +++ b/src/state/actions/index.ts @@ -120,6 +120,7 @@ export default { [context.position.stepId]: true, } } + console.log('progress update', nextProgress) storage.setProgress(nextProgress) return nextProgress } @@ -134,6 +135,7 @@ export default { [context.position.stageId]: true, } } + console.log('progress update', nextProgress) storage.setProgress(nextProgress) return nextProgress } @@ -148,6 +150,7 @@ export default { [context.position.levelId]: true, } } + console.log('progress update', nextProgress) storage.setProgress(nextProgress) return nextProgress @@ -160,20 +163,24 @@ export default { ...context.progress, complete: true, } + console.log('progress update', nextProgress) storage.setProgress(nextProgress) return nextProgress } }), stepLoadNext: assign({ - position: (context: any) => { + position: (context: any): CR.Position => { const { data, position } = context const { stepList } = data.stages[position.stageId] const currentStepIndex = stepList.indexOf(position.stepId) const nextStepId = stepList[currentStepIndex + 1] - return { + + const nextPosition = { ...context.position, stepId: nextStepId, } + console.log('position update', nextPosition) + return nextPosition } }), loadLevel() { From ab0a4bd6242b662566161f42569dca77aa7668dd Mon Sep 17 00:00:00 2001 From: shmck Date: Thu, 13 Jun 2019 21:08:27 -0700 Subject: [PATCH 5/7] fix continue progress --- src/state/actions/index.ts | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/state/actions/index.ts b/src/state/actions/index.ts index 7e13de90..152daab3 100644 --- a/src/state/actions/index.ts +++ b/src/state/actions/index.ts @@ -78,23 +78,31 @@ export default { console.log('ACTION: tutorialLoad.progress') return currentProgress }, - position() { + position(context: any): CR.Position { console.log('ACTION: tutorialLoad.position') if (!currentTutorial) { throw new Error('No Tutorial loaded') } const { data } = currentTutorial - - const levelId = data.summary.levelList[0] - const stageId = data.levels[levelId].stageList[0] - const stepId = data.stages[stageId].stepList[0] + const levelId = data.summary.levelList.find((id: string) => !currentProgress.levels[id]) + if (!levelId) { + throw new Error('No level found on position load') + } + const stageId = data.levels[levelId].stageList.find((id: string) => !currentProgress.stages[id]) + if (!stageId) { + throw new Error('No stage found on position load') + } + const stepId = data.stages[stageId].stepList.find((id: string) => !currentProgress.steps[id]) + if (!stepId) { + throw new Error('No step found on position load') + } const position = { levelId, stageId, - stepId, + stepId } - + console.log('position', position) return position } }), From e7c567038083d305455d1c23248402388324b1d3 Mon Sep 17 00:00:00 2001 From: shmck Date: Thu, 13 Jun 2019 21:08:36 -0700 Subject: [PATCH 6/7] fix guard on final step --- src/state/guards/index.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/state/guards/index.ts b/src/state/guards/index.ts index 04531728..d70e1d87 100644 --- a/src/state/guards/index.ts +++ b/src/state/guards/index.ts @@ -2,11 +2,14 @@ import * as CR from 'typings' export default { hasNextStep: (context: CR.MachineContext): boolean => { - const { data, position } = context + const { data, position, progress } = context const steps = data.stages[position.stageId].stepList - const hasNext = steps[steps.length - 1] !== position.stepId - console.log('GUARD: hasNextStep', hasNext) - return hasNext + // isn't final step yet + if (steps[steps.length - 1] !== position.stepId) { + return true + } + // final step is not yet complete + return !progress.steps[position.stepId] }, hasNextStage: (context: CR.MachineContext): boolean => { const { data, position } = context From e7008f66b6d7c787712f933480467a3e6c8b0b44 Mon Sep 17 00:00:00 2001 From: shmck Date: Thu, 13 Jun 2019 21:08:46 -0700 Subject: [PATCH 7/7] load commits after step completion --- src/state/machine.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/state/machine.ts b/src/state/machine.ts index 45c18283..c28bf1c5 100644 --- a/src/state/machine.ts +++ b/src/state/machine.ts @@ -143,6 +143,7 @@ export const machine = Machine< 0: [{ target: 'Normal', cond: 'hasNextStep', + actions: ['stepLoadCommits'] }, { target: 'StageComplete' }]