Skip to content

Commit ada2f6a

Browse files
authored
Merge pull request #420 from coderoad/feature/completion-hooks
Feature/completion hooks
2 parents 0719328 + 78c2c1d commit ada2f6a

File tree

4 files changed

+63
-9
lines changed

4 files changed

+63
-9
lines changed

Diff for: src/channel.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,13 @@ class Channel implements Channel {
5555
openWorkspace()
5656
return
5757
// load step actions (git commits, commands, open files)
58-
case 'SETUP_ACTIONS':
58+
case 'EDITOR_LEVEL_ENTER':
59+
case 'EDITOR_STEP_ENTER':
5960
await vscode.commands.executeCommand(COMMANDS.SET_CURRENT_POSITION, action.payload.position)
6061
hooks.onSetupEnter(action.payload.actions)
6162
return
6263
// load solution step actions (git commits, commands, open files)
63-
case 'SOLUTION_ACTIONS':
64+
case 'EDITOR_SOLUTION_ENTER':
6465
await vscode.commands.executeCommand(COMMANDS.SET_CURRENT_POSITION, action.payload.position)
6566
hooks.onSolutionEnter(action.payload.actions)
6667
return
@@ -80,6 +81,15 @@ class Channel implements Channel {
8081
case 'EDITOR_RUN_RESET_POSITION':
8182
actions.onRunReset({ type: 'POSITION', position: action.payload.position }, this.context)
8283
return
84+
case 'EDITOR_STEP_COMPLETE':
85+
hooks.onStepComplete(action.payload)
86+
return
87+
case 'EDITOR_LEVEL_COMPLETE':
88+
hooks.onLevelComplete(action.payload)
89+
return
90+
case 'EDITOR_TUTORIAL_COMPLETE':
91+
hooks.onTutorialComplete(action.payload)
92+
return
8393
default:
8494
logger(`No match for action type: ${actionType}`)
8595
return

Diff for: src/services/hooks/index.ts

+14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as T from 'typings'
12
import * as TT from 'typings/tutorial'
23
import * as git from '../git'
34
import loadCommits from './utils/loadCommits'
@@ -7,6 +8,7 @@ import runCommands from './utils/runCommands'
78
import runVSCodeCommands from './utils/runVSCodeCommands'
89
import { onError as telemetryOnError } from '../telemetry'
910
import { onRunTest } from '../../actions/onTest'
11+
import logger from '../logger'
1012

1113
export const onInit = async (actions: TT.StepActions): Promise<void> => {
1214
await loadCommits(actions?.commits)
@@ -39,3 +41,15 @@ export const onSolutionEnter = async (actions: TT.StepActions): Promise<void> =>
3941
export const onError = async (error: Error): Promise<void> => {
4042
telemetryOnError(error)
4143
}
44+
45+
export const onStepComplete = async ({ levelId, stepId }: { levelId: string; stepId: string }): Promise<void> => {
46+
logger(`ON STEP COMPLETE: ${JSON.stringify({ levelId, stepId })}`)
47+
}
48+
49+
export const onLevelComplete = async ({ levelId }: { levelId: string }): Promise<void> => {
50+
logger(`ON LEVEL COMPLETE: ${JSON.stringify(levelId)}`)
51+
}
52+
53+
export const onTutorialComplete = async ({ tutorialId }: { tutorialId: string }): Promise<void> => {
54+
logger(`ON TUTORIAL COMPLETE: ${JSON.stringify(tutorialId)}`)
55+
}

Diff for: web-app/src/services/state/actions/editor.ts

+28-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export default (editorSend: any) => ({
3232
const step: TT.Step | null = selectors.currentStep(context)
3333
// load step actions
3434
editorSend({
35-
type: 'SETUP_ACTIONS',
35+
type: 'EDITOR_LEVEL_ENTER',
3636
payload: {
3737
position: {
3838
stepId: step?.id || null,
@@ -48,7 +48,7 @@ export default (editorSend: any) => ({
4848
if (step && step.setup) {
4949
// load step actions
5050
editorSend({
51-
type: 'SETUP_ACTIONS',
51+
type: 'EDITOR_STEP_ENTER',
5252
payload: {
5353
// set position here
5454
position: {
@@ -76,7 +76,7 @@ export default (editorSend: any) => ({
7676
// tell editor to load solution commit
7777
if (step && step.solution) {
7878
editorSend({
79-
type: 'SOLUTION_ACTIONS',
79+
type: 'EDITOR_SOLUTION_ENTER',
8080
payload: {
8181
position: {
8282
stepId: step.id,
@@ -133,4 +133,29 @@ export default (editorSend: any) => ({
133133
},
134134
})
135135
},
136+
onStepComplete(context: T.MachineContext): void {
137+
editorSend({
138+
type: 'EDITOR_STEP_COMPLETE',
139+
payload: {
140+
levelId: context.position.levelId,
141+
stepId: context.position.levelId,
142+
},
143+
})
144+
},
145+
onLevelComplete(context: T.MachineContext): void {
146+
editorSend({
147+
type: 'EDITOR_LEVEL_COMPLETE',
148+
payload: {
149+
levelId: context.position.levelId,
150+
},
151+
})
152+
},
153+
onTutorialComplete(context: T.MachineContext): void {
154+
editorSend({
155+
type: 'EDITOR_TUTORIAL_COMPLETE',
156+
payload: {
157+
tutorialId: context.tutorial?.id,
158+
},
159+
})
160+
},
136161
})

Diff for: web-app/src/services/state/machine.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ export const createMachine = (options: any) => {
181181
on: {
182182
TEST_PASS: {
183183
target: 'StepNext',
184-
actions: ['testPass', 'updateStepPosition'],
184+
actions: ['onStepComplete', 'testPass', 'updateStepPosition'],
185185
},
186186
TEST_FAIL: {
187187
target: 'Normal',
@@ -200,7 +200,10 @@ export const createMachine = (options: any) => {
200200
target: 'Normal',
201201
actions: ['loadStep', 'updateStepPosition'],
202202
},
203-
LEVEL_COMPLETE: 'LevelComplete',
203+
LEVEL_COMPLETE: {
204+
target: 'LevelComplete',
205+
actions: ['onLevelComplete'],
206+
},
204207
},
205208
},
206209
LevelComplete: {
@@ -223,14 +226,16 @@ export const createMachine = (options: any) => {
223226
target: 'Load',
224227
actions: ['updatePosition'],
225228
},
226-
COMPLETED: '#completed-tutorial',
229+
COMPLETED: {
230+
target: '#completed-tutorial',
231+
actions: ['onTutorialComplete'],
232+
},
227233
},
228234
},
229235
},
230236
},
231237
Completed: {
232238
id: 'completed-tutorial',
233-
onEntry: ['userTutorialComplete'], // unusued
234239
on: {
235240
SELECT_TUTORIAL: {
236241
target: '#select-new-tutorial',

0 commit comments

Comments
 (0)