Skip to content

Commit 0a781bf

Browse files
committed
further event cleanup
1 parent 9257205 commit 0a781bf

File tree

11 files changed

+140
-134
lines changed

11 files changed

+140
-134
lines changed

src/channel/index.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class Channel implements Channel {
3838
public receive = async (action: EditorEvents) => {
3939
// action may be an object.type or plain string
4040
const actionType: string = typeof action === 'string' ? action : action.type
41+
// @ts-ignore TODO: actual error, fix !
4142
const onError = (error: CR.ErrorMessage) => this.send({ type: 'ERROR', payload: { error } })
4243

4344
switch (actionType) {
@@ -48,17 +49,18 @@ class Channel implements Channel {
4849
env: {
4950
machineId: vscode.env.machineId,
5051
sessionId: vscode.env.sessionId,
52+
token: '',
5153
},
5254
},
5355
})
5456
return
5557
// continue from tutorial from local storage
56-
case 'EDITOR_TUTORIAL_LOAD':
58+
case 'EDITOR_LOAD_STORED_TUTORIAL':
5759
const tutorial: G.Tutorial | null = this.context.tutorial.get()
5860

5961
// new tutorial
6062
if (!tutorial || !tutorial.id || !tutorial.version) {
61-
this.send({ type: 'NEW_TUTORIAL' })
63+
this.send({ type: 'NO_CONTINUE' })
6264
return
6365
}
6466

@@ -67,21 +69,22 @@ class Channel implements Channel {
6769

6870
if (progress.complete) {
6971
// tutorial is already complete
70-
this.send({ type: 'NEW_TUTORIAL' })
72+
this.send({ type: 'NO_CONTINUE' })
7173
return
7274
}
7375

7476
// communicate to client the tutorial & stepProgress state
75-
this.send({ type: 'CONTINUE_TUTORIAL', payload: { tutorial, progress, position } })
77+
this.send({ type: 'CAN_CONTINUE', payload: { tutorial, progress, position } })
7678

7779
return
7880
// clear tutorial local storage
79-
case 'TUTORIAL_CLEAR':
81+
case 'EDITOR_CLEAR_TUTORIAL_STORAGE':
8082
// clear current progress/position/tutorial
8183
this.context.reset()
8284
return
8385
// configure test runner, language, git
8486
case 'EDITOR_TUTORIAL_CONFIG':
87+
// @ts-ignore TODO: fix typings
8588
const tutorialData: G.Tutorial = action.payload.tutorial
8689
// setup tutorial config (save watcher, test runner, etc)
8790
this.context.setTutorial(this.workspaceState, tutorialData)
@@ -107,17 +110,22 @@ class Channel implements Channel {
107110
onError,
108111
)
109112
// update the current stepId on startup
113+
// @ts-ignore TODO: fix typings
110114
vscode.commands.executeCommand(COMMANDS.SET_CURRENT_STEP, action.payload)
111115
return
112116
// load step actions (git commits, commands, open files)
113117
case 'SETUP_ACTIONS':
118+
// @ts-ignore TODO: fix typings
114119
await vscode.commands.executeCommand(COMMANDS.SET_CURRENT_STEP, action.payload)
120+
// @ts-ignore TODO: fix typings
115121
setupActions(this.workspaceRoot, action.payload, this.send)
116122
return
117123
// load solution step actions (git commits, commands, open files)
118124
case 'SOLUTION_ACTIONS':
125+
// @ts-ignore TODO: fix typings
119126
await solutionActions(this.workspaceRoot, action.payload, this.send)
120127
// run test following solution to update position
128+
// @ts-ignore TODO: fix typings
121129
vscode.commands.executeCommand(COMMANDS.RUN_TEST, action.payload)
122130
return
123131

@@ -133,6 +141,7 @@ class Channel implements Channel {
133141
switch (actionType) {
134142
case 'TEST_PASS':
135143
// update local storage stepProgress
144+
// @ts-ignore TODO: fix typings
136145
const progress = this.context.progress.setStepComplete(action.payload.stepId)
137146
const tutorial = this.context.tutorial.get()
138147
if (!tutorial) {

typings/events.d.ts

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,33 @@
11
import * as CR from './index'
22
import * as G from './graphql'
33

4-
/* --- Editor Events --- */
4+
/*
5+
--- Editor Events ---
6+
sent from client to editor
7+
*/
58

6-
export type EnvGetEvent = { type: 'ENV_LOAD'; payload: { env: CR.Environment } }
9+
export type EnvGetEvent = { type: 'ENV_GET' }
710
export type EditorTutorialConfigEvent = { type: 'EDITOR_TUTORIAL_CONFIG'; payload: { tutorial: G.Tutorial } }
811
export type StepActionsEvent = { type: 'SETUP_ACTIONS'; payload: CR.StepActions }
912
export type SolutionActionsEvent = { type: 'SOLUTION_ACTIONS'; payload: CR.StepActions }
1013

1114
export type EditorEvents =
1215
| EnvGetEvent
13-
| { type: 'EDITOR_TUTORIAL_LOAD' }
14-
| { type: 'TUTORIAL_CLEAR' }
16+
| { type: 'EDITOR_LOAD_STORED_TUTORIAL' }
17+
| { type: 'EDITOR_CLEAR_TUTORIAL_STORAGE' }
1518
| EditorTutorialConfigEvent
1619
| { type: 'EDITOR_TUTORIAL_CONTINUE_CONFIG' }
1720
| StepActionsEvent
1821
| SolutionActionsEvent
1922

20-
/* --- Client Events --- */
23+
/*
24+
--- Client Events ---
25+
sent within client
26+
or sent from editor to client
27+
*/
2128

2229
export type EventLoadEvent = { type: 'ENV_LOAD'; payload: { env: CR.Environment } }
23-
export type ErrorEvent = { type: 'ERROR'; payload: { error: string } }
30+
export type ErrorMessageEvent = { type: 'ERROR'; payload: CR.ErrorMessage }
2431
export type CommandStartEvent = { type: 'COMMAND_START'; payload: { process: CR.ProcessEvent } }
2532
export type CommandSuccessEvent = { type: 'COMMAND_SUCCESS'; payload: { process: CR.ProcessEvent } }
2633
export type CommandFailEvent = { type: 'COMMAND_FAIL'; payload: { process: CR.ProcessEvent } }
@@ -31,8 +38,8 @@ export type NextLevelEvent = { type: 'NEXT_LEVEL'; payload: { position: CR.Posit
3138
export type TestRunningEvent = { type: 'TEST_RUNNING'; payload: { stepId: string } }
3239
export type TestErrorEvent = { type: 'TEST_ERROR'; payload: { stepId: string } }
3340
export type LoadNextStepEvent = { type: 'LOAD_NEXT_STEP'; payload: { step: string } }
34-
export type ContinueTutorialEvent = {
35-
type: 'CONTINUE_TUTORIAL'
41+
export type CanContinueEvent = {
42+
type: 'CAN_CONTINUE'
3643
payload: { tutorial: G.Tutorial; progress: CR.Progress; position: CR.Position }
3744
}
3845
export type LoadTutorialEvent = { type: 'LOAD_TUTORIAL'; payload: { tutorial: G.Tutorial } }
@@ -58,14 +65,14 @@ export type PlayTutorialEvents =
5865
| { type: 'EXIT' }
5966

6067
export type SelectTutorialEvents =
61-
| ContinueTutorialEvent
68+
| { type: 'NO_CONTINUE' }
69+
| CanContinueEvent
6270
| LoadTutorialEvent
63-
| { type: 'NEW_TUTORIAL' }
6471
| { type: 'BACK' }
6572
| TutorialSelectedEvent
6673
| { type: 'TUTORIAL_CONFIGURED' }
67-
| { type: 'SELECT_NEW_TUTORIAL' }
68-
| { type: 'TUTORIAL_START' }
74+
| { type: 'CHOOSE_NEW' }
75+
| { type: 'CHOOSE_CONTINUE' }
6976
| ErrorEvent
7077

71-
type ClientEvents = MachineEvent | AuthenticateEvents | SelectTutorialEvents | PlayTutorialEvents
78+
type ClientEvents = AuthenticateEvents | SelectTutorialEvents | PlayTutorialEvents

web-app/src/components/Debugger/index.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@ interface Props extends MachineContext {
77
children: React.ReactElement
88
}
99

10-
const Debugger = ({ state, children, env, position, progress, processes, tutorial }: Props) => (
10+
const Debugger = ({ state, children, position, progress, processes, tutorial }: Props) => (
1111
<div css={{ backgroundColor: '#FFFF99', color: 'black', padding: '.5rem' }}>
1212
<h4>state: {state}</h4>
13-
<p>MachineId: {env.machineId}</p>
14-
<p>SessionId: {env.sessionId}</p>
1513
<p>tutorial: {tutorial ? tutorial.id : 'none'}</p>
1614
<p css={{ backgroundColor: 'khaki', padding: '.5rem' }}>position: {JSON.stringify(position)}</p>
1715
<p css={{ backgroundColor: 'moccasin', padding: '.5rem' }}>progress: {JSON.stringify(progress)}</p>

web-app/src/containers/Continue/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ const ContinuePageContainer = ({ context, send }: ContainerProps) => {
6262
return (
6363
<ContinuePage
6464
tutorial={tutorial}
65-
onContinue={() => send({ type: 'TUTORIAL_START' })}
66-
onNew={() => send({ type: 'SELECT_NEW_TUTORIAL' })}
65+
onContinue={() => send({ type: 'CHOOSE_CONTINUE' })}
66+
onNew={() => send({ type: 'CHOOSE_NEW' })}
6767
/>
6868
)
6969
}

web-app/src/services/channel/mock.ts

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
1-
import { ClientEvents } from 'typings/events'
2-
import channel from './index'
1+
// import { ClientEvents } from 'typings/events'
2+
// import channel from './index'
33

4-
const createReceiveEvent = (action: ClientEvents) => ({
5-
data: action,
6-
})
4+
// const createReceiveEvent = (action: ClientEvents) => ({
5+
// data: action,
6+
// })
77

88
// mock vscode from client side development
99
// @ts-ignore
1010
window.acquireVsCodeApi = () => ({
11-
postMessage(action: ClientEvents) {
12-
switch (action.type) {
13-
case 'TUTORIAL_START':
14-
return setTimeout(() => {
15-
const receiveAction: ClientEvents = {
16-
type: 'TUTORIAL_LOADED',
17-
}
18-
channel.receive(createReceiveEvent(receiveAction))
19-
}, 1000)
20-
case 'TEST_RUN':
21-
return setTimeout(() => {
22-
const receiveAction: ClientEvents = {
23-
type: 'TEST_PASS',
24-
payload: action.payload,
25-
}
26-
channel.receive(createReceiveEvent(receiveAction))
27-
}, 1000)
28-
default:
29-
console.warn(`${action.type} not found in post message mock`)
30-
}
31-
},
11+
// postMessage(action: ClientEvents) {
12+
// switch (action.type) {
13+
// case 'CHOOSE_CONTINUE':
14+
// return setTimeout(() => {
15+
// const receiveAction: ClientEvents = {
16+
// type: 'TUTORIAL_LOADED',
17+
// }
18+
// channel.receive(createReceiveEvent(receiveAction))
19+
// }, 1000)
20+
// case 'TEST_RUN':
21+
// return setTimeout(() => {
22+
// const receiveAction: ClientEvents = {
23+
// type: 'TEST_PASS',
24+
// payload: action.payload,
25+
// }
26+
// channel.receive(createReceiveEvent(receiveAction))
27+
// }, 1000)
28+
// default:
29+
// console.warn(`${action.type} not found in post message mock`)
30+
// }
31+
// },
3232
})
Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,4 @@
1-
import { createSelector } from 'reselect'
2-
import * as CR from 'typings'
3-
import * as G from 'typings/graphql'
4-
import * as tutorial from './tutorial'
5-
61
export const defaultPosition = () => ({
72
levelId: '',
83
stepId: '',
94
})
10-
11-
export const initialPosition = createSelector(tutorial.currentVersion, (version: G.TutorialVersion) => {
12-
const level = version.data.levels[0]
13-
const position: CR.Position = {
14-
levelId: level.id,
15-
stepId: level.steps[0].id,
16-
}
17-
return position
18-
})

web-app/src/services/state/authenticate/actions.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as CR from 'typings'
22
import * as G from 'typings/graphql'
3-
import { AuthenticateEvents, EnvGetEvent } from 'typings/events'
3+
import { AuthenticateEvents, EventLoadEvent, ErrorMessageEvent } from 'typings/events'
44
import { assign, ActionFunctionMap } from 'xstate'
55
import client from '../../apollo'
66
import { setAuthToken } from '../../apollo/auth'
@@ -23,9 +23,14 @@ interface AuthenticateVariables {
2323
}
2424

2525
const actions: ActionFunctionMap<MachineContext, AuthenticateEvents> = {
26+
loadEnv(): void {
27+
channel.editorSend({
28+
type: 'ENV_GET',
29+
})
30+
},
2631
// @ts-ignore
2732
setEnv: assign({
28-
env: (context: MachineContext, event: EnvGetEvent): CR.Environment => ({
33+
env: (context: MachineContext, event: EventLoadEvent): CR.Environment => ({
2934
...context.env,
3035
...event.payload.env,
3136
}),
@@ -56,7 +61,8 @@ const actions: ActionFunctionMap<MachineContext, AuthenticateEvents> = {
5661
description: error.message,
5762
}
5863
}
59-
channel.receive({ data: ErrorEvent })
64+
// TODO: fix
65+
// channel.receive({ data: { payload: message } })
6066
return
6167
})
6268

web-app/src/services/state/playTutorial/actions.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ const actions: ActionFunctionMap<MachineContext, Event.PlayTutorialEvents> = {
200200
),
201201
// @ts-ignore
202202
setError: assign({
203-
error: (context: MachineContext, event: Event.ErrorEvent): string | null => {
204-
return event.payload.error
203+
error: (context: MachineContext, event: Event.ErrorMessageEvent): string | null => {
204+
return event.payload.title
205205
},
206206
}),
207207
loadLevel(context: MachineContext): void {
@@ -239,7 +239,7 @@ const actions: ActionFunctionMap<MachineContext, Event.PlayTutorialEvents> = {
239239
})
240240
},
241241
clearStorage(): void {
242-
channel.editorSend({ type: 'TUTORIAL_CLEAR' })
242+
channel.editorSend({ type: 'EDITOR_CLEAR_TUTORIAL_STORAGE' })
243243
},
244244
}
245245

web-app/src/services/state/playTutorial/index.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ export type StateSchema = {
2626

2727
export type MachineContext = {
2828
error: CR.ErrorMessage | null
29-
env: CR.Environment
3029
tutorial: G.Tutorial | null
3130
position: CR.Position
3231
progress: CR.Progress
@@ -45,7 +44,6 @@ export const playTutorialMachine = Machine<MachineContext, StateSchema, PlayTuto
4544
{
4645
context: {
4746
error: null,
48-
env: { machineId: '', sessionId: '', token: '' },
4947
tutorial: null,
5048
position: { levelId: '', stepId: '' },
5149
progress: {
@@ -57,7 +55,6 @@ export const playTutorialMachine = Machine<MachineContext, StateSchema, PlayTuto
5755
},
5856
id: 'tutorial',
5957
initial: 'Level',
60-
onEntry: ['initTutorial'],
6158
on: {
6259
// track commands
6360
COMMAND_START: {

0 commit comments

Comments
 (0)