Skip to content

prevent commands on reset tutorial #439

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 2 commits into from
Aug 8, 2020
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,3 +248,8 @@ Adds a review page for viewing tutorial content. The review page should be espec
- Supports commands on reset
- Supports running vscode commands anywhere that command line commands can be run
- Admin mode to allow creators to jump between tutorial levels/steps during development

### [0.13.1]

- Add logo
- Fix issue with watcher tests running on reset
4 changes: 2 additions & 2 deletions src/services/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import * as T from 'typings'
import * as TT from 'typings/tutorial'
import * as git from '../git'
import loadCommits from './utils/loadCommits'
import loadWatchers from './utils/loadWatchers'
import { loadWatchers, resetWatchers } from './utils/watchers'
import openFiles from './utils/openFiles'
import runCommands from './utils/runCommands'
import runVSCodeCommands from './utils/runVSCodeCommands'
Expand Down Expand Up @@ -39,6 +38,7 @@ export const onSolutionEnter = async (actions: TT.StepActions): Promise<void> =>
}

export const onReset = async (actions: TT.StepActions): Promise<void> => {
await resetWatchers()
await runCommands(actions?.commands)
await runVSCodeCommands(actions?.vscodeCommands)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const disposeWatcher = (watcher: string) => {
delete watcherObject[watcher]
}

const loadWatchers = (watchers: string[] = []): void => {
export const loadWatchers = (watchers: string[] = []): void => {
if (!watchers.length) {
// remove all watchers
for (const watcher of Object.keys(watcherObject)) {
Expand Down Expand Up @@ -55,4 +55,8 @@ const loadWatchers = (watchers: string[] = []): void => {
}
}

export default loadWatchers
export const resetWatchers = (): void => {
for (const watcher of Object.keys(watcherObject)) {
disposeWatcher(watcher)
}
}
27 changes: 14 additions & 13 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,27 +89,28 @@ export interface MachineStateSchema {
states: {
Setup: {
states: {
Startup: {}
ValidateSetup: {}
Start: {}
SelectTutorial: {}
SetupNewTutorial: {}
StartTutorial: {}
Startup: Record<string, unknown>
ValidateSetup: Record<string, unknown>
Start: Record<string, unknown>
SelectTutorial: Record<string, unknown>
SetupNewTutorial: Record<string, unknown>
StartTutorial: Record<string, unknown>
}
}
Tutorial: {
states: {
Level: {
states: {
Load: {}
Normal: {}
TestRunning: {}
StepNext: {}
LevelComplete: {}
LoadNext: {}
Load: Record<string, unknown>
Normal: Record<string, unknown>
TestRunning: Record<string, unknown>
StepNext: Record<string, unknown>
LevelComplete: Record<string, unknown>
LoadNext: Record<string, unknown>
}
}
Completed: {}
Reset: Record<string, unknown>
Completed: Record<string, unknown>
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions web-app/src/Routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ const Routes = () => {
<Route paths={{ Tutorial: { Level: { Load: true } } }}>
<LoadingPage text="Loading Level..." processes={context.processes} />
</Route>
<Route paths={{ Tutorial: { Reset: true } }}>
<LoadingPage text="Resetting tutorial..." processes={context.processes} />
</Route>
<Route paths={{ Tutorial: { Level: true, Completed: true } }}>
<TutorialPage send={send} context={context} state={route.replace('Tutorial.', '')} />
</Route>
Expand Down
13 changes: 9 additions & 4 deletions web-app/src/services/state/machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ export const createMachine = (options: any) => {
target: 'SetupNewTutorial',
actions: ['setTutorialContext'],
},
// TODO: handle completed tutorial differently
TUTORIAL_ALREADY_COMPLETE: {
target: 'Start',
actions: ['setStart'],
Expand Down Expand Up @@ -168,9 +167,7 @@ export const createMachine = (options: any) => {
RUN_TEST: {
actions: ['runTest'],
},
RUN_RESET: {
actions: ['runReset'],
},
RUN_RESET: '#reset-tutorial',
KEY_PRESS_ENTER: {
actions: ['runTest'],
},
Expand Down Expand Up @@ -234,6 +231,14 @@ export const createMachine = (options: any) => {
},
},
},
Reset: {
id: 'reset-tutorial',
onEntry: ['runReset'],
onExit: ['testClear'],
after: {
3000: '#tutorial',
},
},
Completed: {
id: 'completed-tutorial',
on: {
Expand Down