diff --git a/src/channel/index.ts b/src/channel/index.ts index 4a64f987..c30ceb3f 100644 --- a/src/channel/index.ts +++ b/src/channel/index.ts @@ -48,7 +48,7 @@ class Channel implements Channel { // console.log(`ACTION: ${actionType}`) switch (actionType) { - case 'EDITOR_ENV_GET': + case 'EDITOR_STARTUP': // check if a workspace is open, otherwise nothing works const noActiveWorksapce = !environment.WORKSPACE_ROOT.length if (noActiveWorksapce) { @@ -65,23 +65,18 @@ class Channel implements Channel { this.send({ type: 'NO_WORKSPACE', payload: { error } }) return } - this.send({ - type: 'ENV_LOAD', - payload: { - env: { - machineId: vscode.env.machineId, - sessionId: vscode.env.sessionId, - }, - }, - }) - return - // continue from tutorial from local storage - case 'EDITOR_TUTORIAL_LOAD': + + const env = { + machineId: vscode.env.machineId, + sessionId: vscode.env.sessionId, + } + + // continue from tutorial from local storage const tutorial: TT.Tutorial | null = this.context.tutorial.get() // new tutorial if (!tutorial || !tutorial.id) { - this.send({ type: 'START_NEW_TUTORIAL' }) + this.send({ type: 'START_NEW_TUTORIAL', payload: { env } }) return } @@ -90,13 +85,14 @@ class Channel implements Channel { if (progress.complete) { // tutorial is already complete - this.send({ type: 'START_NEW_TUTORIAL' }) + this.send({ type: 'TUTORIAL_ALREADY_COMPLETE', payload: { env } }) return } // communicate to client the tutorial & stepProgress state - this.send({ type: 'LOAD_STORED_TUTORIAL', payload: { tutorial, progress, position } }) + this.send({ type: 'LOAD_STORED_TUTORIAL', payload: { env, tutorial, progress, position } }) return + // clear tutorial local storage case 'TUTORIAL_CLEAR': // clear current progress/position/tutorial diff --git a/typings/index.d.ts b/typings/index.d.ts index 2b8c8d22..8d07d8a5 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -65,7 +65,6 @@ export interface MachineStateSchema { Setup: { states: { Startup: {} - LoadStoredTutorial: {} Start: {} ValidateSetup: {} SelectTutorial: {} diff --git a/web-app/src/Routes.tsx b/web-app/src/Routes.tsx index 4754bf62..84b2ccda 100644 --- a/web-app/src/Routes.tsx +++ b/web-app/src/Routes.tsx @@ -24,7 +24,7 @@ const Routes = () => { {/* Setup */} - + diff --git a/web-app/src/services/state/actions/context.ts b/web-app/src/services/state/actions/context.ts index 8d9f08e9..8dd3f083 100644 --- a/web-app/src/services/state/actions/context.ts +++ b/web-app/src/services/state/actions/context.ts @@ -6,7 +6,7 @@ import onError from '../../../services/sentry/onError' const contextActions: ActionFunctionMap = { // @ts-ignore - setEnv: assign({ + setStart: assign({ env: (context: T.MachineContext, event: T.MachineEvent) => { return { ...context.env, @@ -16,6 +16,12 @@ const contextActions: ActionFunctionMap = { }), // @ts-ignore storeContinuedTutorial: assign({ + env: (context: T.MachineContext, event: T.MachineEvent) => { + return { + ...context.env, + ...event.payload.env, + } + }, tutorial: (context: T.MachineContext, event: T.MachineEvent) => { return event.payload.tutorial }, diff --git a/web-app/src/services/state/actions/editor.ts b/web-app/src/services/state/actions/editor.ts index a99ad326..e8352bd5 100644 --- a/web-app/src/services/state/actions/editor.ts +++ b/web-app/src/services/state/actions/editor.ts @@ -3,16 +3,9 @@ import * as TT from 'typings/tutorial' import * as selectors from '../../selectors' export default (editorSend: any) => ({ - loadEnv(): void { + startup(): void { editorSend({ - type: 'EDITOR_ENV_GET', - }) - }, - loadStoredTutorial(): void { - // send message to editor to see if there is existing tutorial progress - // in local storage on the editor - editorSend({ - type: 'EDITOR_TUTORIAL_LOAD', + type: 'EDITOR_STARTUP', }) }, configureNewTutorial(context: CR.MachineContext) { diff --git a/web-app/src/services/state/machine.ts b/web-app/src/services/state/machine.ts index 787d5f73..befba922 100644 --- a/web-app/src/services/state/machine.ts +++ b/web-app/src/services/state/machine.ts @@ -34,37 +34,27 @@ export const createMachine = (options: any) => { initial: 'Startup', states: { Startup: { - onEntry: ['loadEnv'], + onEntry: ['startup'], onExit: ['clearError'], on: { - ENV_LOAD: { - target: 'LoadStoredTutorial', - actions: ['setEnv'], - }, NO_WORKSPACE: { actions: ['setError'], }, REQUEST_WORKSPACE: { actions: 'requestWorkspaceSelect', }, - }, - }, - LoadStoredTutorial: { - onEntry: ['loadStoredTutorial'], - on: { LOAD_STORED_TUTORIAL: { target: 'Start', actions: ['storeContinuedTutorial'], }, - START_NEW_TUTORIAL: 'Start', - }, - }, - Start: { - on: { - NEW_TUTORIAL: 'ValidateSetup', - CONTINUE_TUTORIAL: { - target: '#tutorial-level', - actions: ['continueConfig'], + START_NEW_TUTORIAL: { + target: 'Start', + actions: ['setStart'], + }, + // TODO: handle completed tutorial differently + TUTORIAL_ALREADY_COMPLETE: { + target: 'Start', + actions: ['setStart'], }, }, }, @@ -83,6 +73,15 @@ export const createMachine = (options: any) => { SETUP_VALIDATED: 'SelectTutorial', }, }, + Start: { + on: { + NEW_TUTORIAL: 'ValidateSetup', + CONTINUE_TUTORIAL: { + target: '#tutorial-level', + actions: ['continueConfig'], + }, + }, + }, SelectTutorial: { onEntry: ['clearStorage'], id: 'select-new-tutorial',