Skip to content

Refactor #441

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 4 commits into from
Aug 9, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix bug with continue loading init commits
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
  • Loading branch information
ShMcK committed Aug 8, 2020
commit 4044c7f8229e6584f5992198abbaa12ff536344f
6 changes: 3 additions & 3 deletions src/actions/onStartup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ const onStartup = async (context: Context): Promise<void> => {
// continue from tutorial from local storage
const tutorial: TT.Tutorial | null = context.tutorial.get()

// no stored tutorial, must start new tutorial
// NEW: no stored tutorial, must start new tutorial
if (!tutorial || !tutorial.id) {
if (TUTORIAL_URL) {
if (!!TUTORIAL_URL) {
// NEW_FROM_URL
try {
const tutorialRes = await fetch(TUTORIAL_URL)
Expand All @@ -47,7 +47,7 @@ const onStartup = async (context: Context): Promise<void> => {
console.log(`Failed to load tutorial from url ${TUTORIAL_URL} with error "${e.message}"`)
}
}
// NEW
// NEW from start click
send({ type: 'START_NEW_TUTORIAL', payload: { env } })
return
}
Expand Down
12 changes: 7 additions & 5 deletions src/actions/onTutorialConfigContinue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@ import * as TT from 'typings/tutorial'
import Context from '../services/context/context'
import tutorialConfig from './utils/tutorialConfig'
import { COMMANDS, send } from '../commands'
import logger from '../services/logger'

const onTutorialConfigContinue = async (action: T.Action, context: Context): Promise<void> => {
logger('onTutorialConfigContinue', action)
try {
const tutorialContinue: TT.Tutorial | null = context.tutorial.get()
if (!tutorialContinue) {
const tutorialToContinue: TT.Tutorial | null = context.tutorial.get()
if (!tutorialToContinue) {
throw new Error('Invalid tutorial to continue')
}
// update the current stepId on startup
vscode.commands.executeCommand(COMMANDS.SET_CURRENT_POSITION, action.payload.position)
await tutorialConfig({
data: tutorialContinue,
data: tutorialToContinue,
alreadyConfigured: true,
})
// update the current stepId on startup
vscode.commands.executeCommand(COMMANDS.SET_CURRENT_POSITION, action.payload.position)
} catch (e) {
const error = {
type: 'UnknownError',
Expand Down
2 changes: 1 addition & 1 deletion src/actions/utils/tutorialConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const tutorialConfig = async ({ data, alreadyConfigured }: TutorialConfigParams)
}
}

await vscode.commands.executeCommand(COMMANDS.CONFIG_TEST_RUNNER, data)
await vscode.commands.executeCommand(COMMANDS.CONFIG_TEST_RUNNER, { data, alreadyConfigured })

if (!DISABLE_RUN_ON_SAVE) {
// verify if file test should run based on document saved
Expand Down
16 changes: 12 additions & 4 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,18 @@ export const createCommands = ({ extensionPath, workspaceState }: CreateCommandP
sendToClient = webview.send
}
},
[COMMANDS.CONFIG_TEST_RUNNER]: async (data: TT.Tutorial) => {
const setupActions = data.config.setup
if (setupActions) {
hooks.onInit(setupActions)
[COMMANDS.CONFIG_TEST_RUNNER]: async ({
data,
alreadyConfigured,
}: {
data: TT.Tutorial
alreadyConfigured: boolean
}) => {
if (!alreadyConfigured) {
const setupActions = data.config.setup
if (setupActions) {
hooks.onInit(setupActions)
}
}
testRunner = createTestRunner(data, {
onSuccess: (position: T.Position) => {
Expand Down
4 changes: 3 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import * as vscode from 'vscode'
import { createCommands } from './commands'
import * as telemetry from './services/telemetry'

let onDeactivate = () => {}
let onDeactivate = () => {
/* placeholder for unsubscribing fn */
}

// activate run on vscode extension initialization
export const activate = (vscodeExt: vscode.ExtensionContext): void => {
Expand Down
18 changes: 8 additions & 10 deletions web-app/src/services/state/actions/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,14 @@ export const setStart = assign({
},
})

export const loadContinuedTutorial = assign((context: T.MachineContext, event: T.MachineEvent): any => {
return {
env: {
...context.env,
...event.payload.env,
},
tutorial: event.payload.tutorial,
position: event.payload.position,
}
})
export const loadContinuedTutorial = assign((context: T.MachineContext, event: T.MachineEvent): any => ({
env: {
...context.env,
...event.payload.env,
},
tutorial: event.payload.tutorial,
position: event.payload.position,
}))

export const initPosition = assign({
position: (context: T.MachineContext, event: T.MachineEvent): any => {
Expand Down