Skip to content

Feature/completion hooks #420

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
Aug 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,13 @@ class Channel implements Channel {
openWorkspace()
return
// load step actions (git commits, commands, open files)
case 'SETUP_ACTIONS':
case 'EDITOR_LEVEL_ENTER':
case 'EDITOR_STEP_ENTER':
await vscode.commands.executeCommand(COMMANDS.SET_CURRENT_POSITION, action.payload.position)
hooks.onSetupEnter(action.payload.actions)
return
// load solution step actions (git commits, commands, open files)
case 'SOLUTION_ACTIONS':
case 'EDITOR_SOLUTION_ENTER':
await vscode.commands.executeCommand(COMMANDS.SET_CURRENT_POSITION, action.payload.position)
hooks.onSolutionEnter(action.payload.actions)
return
Expand All @@ -80,6 +81,15 @@ class Channel implements Channel {
case 'EDITOR_RUN_RESET_POSITION':
actions.onRunReset({ type: 'POSITION', position: action.payload.position }, this.context)
return
case 'EDITOR_STEP_COMPLETE':
hooks.onStepComplete(action.payload)
return
case 'EDITOR_LEVEL_COMPLETE':
hooks.onLevelComplete(action.payload)
return
case 'EDITOR_TUTORIAL_COMPLETE':
hooks.onTutorialComplete(action.payload)
return
default:
logger(`No match for action type: ${actionType}`)
return
Expand Down
14 changes: 14 additions & 0 deletions src/services/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as T from 'typings'
import * as TT from 'typings/tutorial'
import * as git from '../git'
import loadCommits from './utils/loadCommits'
Expand All @@ -7,6 +8,7 @@ import runCommands from './utils/runCommands'
import runVSCodeCommands from './utils/runVSCodeCommands'
import { onError as telemetryOnError } from '../telemetry'
import { onRunTest } from '../../actions/onTest'
import logger from '../logger'

export const onInit = async (actions: TT.StepActions): Promise<void> => {
await loadCommits(actions?.commits)
Expand Down Expand Up @@ -39,3 +41,15 @@ export const onSolutionEnter = async (actions: TT.StepActions): Promise<void> =>
export const onError = async (error: Error): Promise<void> => {
telemetryOnError(error)
}

export const onStepComplete = async ({ levelId, stepId }: { levelId: string; stepId: string }): Promise<void> => {
logger(`ON STEP COMPLETE: ${JSON.stringify({ levelId, stepId })}`)
}

export const onLevelComplete = async ({ levelId }: { levelId: string }): Promise<void> => {
logger(`ON LEVEL COMPLETE: ${JSON.stringify(levelId)}`)
}

export const onTutorialComplete = async ({ tutorialId }: { tutorialId: string }): Promise<void> => {
logger(`ON TUTORIAL COMPLETE: ${JSON.stringify(tutorialId)}`)
}
31 changes: 28 additions & 3 deletions web-app/src/services/state/actions/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default (editorSend: any) => ({
const step: TT.Step | null = selectors.currentStep(context)
// load step actions
editorSend({
type: 'SETUP_ACTIONS',
type: 'EDITOR_LEVEL_ENTER',
payload: {
position: {
stepId: step?.id || null,
Expand All @@ -48,7 +48,7 @@ export default (editorSend: any) => ({
if (step && step.setup) {
// load step actions
editorSend({
type: 'SETUP_ACTIONS',
type: 'EDITOR_STEP_ENTER',
payload: {
// set position here
position: {
Expand Down Expand Up @@ -76,7 +76,7 @@ export default (editorSend: any) => ({
// tell editor to load solution commit
if (step && step.solution) {
editorSend({
type: 'SOLUTION_ACTIONS',
type: 'EDITOR_SOLUTION_ENTER',
payload: {
position: {
stepId: step.id,
Expand Down Expand Up @@ -133,4 +133,29 @@ export default (editorSend: any) => ({
},
})
},
onStepComplete(context: T.MachineContext): void {
editorSend({
type: 'EDITOR_STEP_COMPLETE',
payload: {
levelId: context.position.levelId,
stepId: context.position.levelId,
},
})
},
onLevelComplete(context: T.MachineContext): void {
editorSend({
type: 'EDITOR_LEVEL_COMPLETE',
payload: {
levelId: context.position.levelId,
},
})
},
onTutorialComplete(context: T.MachineContext): void {
editorSend({
type: 'EDITOR_TUTORIAL_COMPLETE',
payload: {
tutorialId: context.tutorial?.id,
},
})
},
})
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 @@ -181,7 +181,7 @@ export const createMachine = (options: any) => {
on: {
TEST_PASS: {
target: 'StepNext',
actions: ['testPass', 'updateStepPosition'],
actions: ['onStepComplete', 'testPass', 'updateStepPosition'],
},
TEST_FAIL: {
target: 'Normal',
Expand All @@ -200,7 +200,10 @@ export const createMachine = (options: any) => {
target: 'Normal',
actions: ['loadStep', 'updateStepPosition'],
},
LEVEL_COMPLETE: 'LevelComplete',
LEVEL_COMPLETE: {
target: 'LevelComplete',
actions: ['onLevelComplete'],
},
},
},
LevelComplete: {
Expand All @@ -223,14 +226,16 @@ export const createMachine = (options: any) => {
target: 'Load',
actions: ['updatePosition'],
},
COMPLETED: '#completed-tutorial',
COMPLETED: {
target: '#completed-tutorial',
actions: ['onTutorialComplete'],
},
},
},
},
},
Completed: {
id: 'completed-tutorial',
onEntry: ['userTutorialComplete'], // unusued
on: {
SELECT_TUTORIAL: {
target: '#select-new-tutorial',
Expand Down