Skip to content

Commit e3a7753

Browse files
committed
move summary & configure into SelectTutorial (broken)
1 parent 072e25b commit e3a7753

File tree

6 files changed

+48
-50
lines changed

6 files changed

+48
-50
lines changed

typings/index.d.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,19 @@ export interface SelectTutorialMachineStateSchema {
6666
Authenticate: {}
6767
NewOrContinue: {}
6868
SelectTutorial: {}
69+
Summary: {}
70+
Configure: {}
71+
Launch: {}
6972
ContinueTutorial: {}
7073
}
7174
}
7275

7376
export interface PlayTutorialMachineStateSchema {
7477
states: {
75-
Initialize: {}
76-
Summary: {}
7778
LoadNext: {}
7879
Level: {
7980
states: {
80-
Load: {}
81+
Loading: {}
8182
Normal: {}
8283
TestRunning: {}
8384
TestPass: {}

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

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@ import * as selectors from '../../../selectors'
55
import onError from '../../../sentry/onError'
66

77
export default {
8-
initTutorial: assign({
9-
// loads complete tutorial
10-
tutorial: (context: CR.PlayMachineContext, event: CR.MachineEvent): any => {
11-
return event.payload.tutorial
12-
},
13-
}),
148
// @ts-ignore
159
initPosition: assign({
1610
position: (context: CR.PlayMachineContext, event: CR.MachineEvent): CR.Position => {
@@ -174,19 +168,6 @@ export default {
174168
}
175169
},
176170
),
177-
reset: assign({
178-
tutorial() {
179-
return null
180-
},
181-
progress(): CR.Progress {
182-
const progress: CR.Progress = selectors.defaultProgress()
183-
return progress
184-
},
185-
position(): CR.Position {
186-
const position: CR.Position = selectors.defaultPosition()
187-
return position
188-
},
189-
}),
190171
// @ts-ignore
191172
setError: assign({
192173
error: (context: CR.PlayMachineContext, event: CR.MachineEvent): string | null => {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ interface TutorialDataVariables {
1616
}
1717

1818
export default {
19-
initializeTutorial(context: CR.PlayMachineContext, event: CR.MachineEvent) {
19+
configureTutorial(context: CR.PlayMachineContext, event: CR.MachineEvent) {
2020
// setup test runner and git
2121
if (!context.tutorial) {
2222
const error = new Error('Tutorial not available to load')

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

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ import { Machine, MachineOptions } from 'xstate'
33
import actions from './actions'
44

55
const options: MachineOptions<CR.PlayMachineContext, CR.MachineEvent> = {
6-
// @ts-ignore
6+
activities: {},
77
actions,
8+
guards: {},
9+
services: {},
10+
delays: {},
811
}
912

1013
export const playTutorialMachine = Machine<CR.PlayMachineContext, CR.PlayTutorialMachineStateSchema, CR.MachineEvent>(
@@ -22,7 +25,8 @@ export const playTutorialMachine = Machine<CR.PlayMachineContext, CR.PlayTutoria
2225
processes: [],
2326
},
2427
id: 'tutorial',
25-
initial: 'Initialize',
28+
initial: 'Level',
29+
onEntry: ['initPosition', 'initTutorial'],
2630
on: {
2731
// track commands
2832
COMMAND_START: {
@@ -39,22 +43,6 @@ export const playTutorialMachine = Machine<CR.PlayMachineContext, CR.PlayTutoria
3943
},
4044
},
4145
states: {
42-
// TODO move Initialize into New Tutorial setup
43-
Initialize: {
44-
onEntry: ['initializeTutorial'],
45-
on: {
46-
TUTORIAL_CONFIGURED: 'Summary',
47-
// TUTORIAL_CONFIG_ERROR: 'Start' // TODO should handle error
48-
},
49-
},
50-
Summary: {
51-
on: {
52-
LOAD_TUTORIAL: {
53-
target: 'Level',
54-
actions: ['initPosition', 'initTutorial'],
55-
},
56-
},
57-
},
5846
LoadNext: {
5947
id: 'tutorial-load-next',
6048
onEntry: ['loadNext'],
@@ -64,16 +52,17 @@ export const playTutorialMachine = Machine<CR.PlayMachineContext, CR.PlayTutoria
6452
actions: ['updatePosition'],
6553
},
6654
NEXT_LEVEL: {
67-
target: 'Level', // TODO should return to levels summary page
55+
target: 'Level',
6856
actions: ['updatePosition'],
6957
},
7058
COMPLETED: '#completed-tutorial',
7159
},
7260
},
7361
Level: {
74-
initial: 'Load',
62+
id: 'level',
63+
initial: 'Loading',
7564
states: {
76-
Load: {
65+
Loading: {
7766
onEntry: ['loadLevel', 'loadStep'],
7867
after: {
7968
0: 'Normal',
@@ -143,7 +132,6 @@ export const playTutorialMachine = Machine<CR.PlayMachineContext, CR.PlayTutoria
143132
on: {
144133
SELECT_TUTORIAL: {
145134
type: 'final',
146-
actions: ['reset'],
147135
},
148136
},
149137
},

web-app/src/services/state/selectTutorial/actions/context.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ export default {
3232
return { levels: {}, steps: {}, complete: false }
3333
},
3434
}),
35+
initTutorial: assign({
36+
// loads complete tutorial
37+
tutorial: (context: CR.PlayMachineContext, event: CR.MachineEvent): any => {
38+
return event.payload.tutorial
39+
},
40+
}),
3541
// @ts-ignore
3642
setError: assign({
3743
error: (context: CR.MachineContext, event: CR.MachineEvent): string | null => {

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

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ import { Machine, MachineOptions } from 'xstate'
33
import actions from './actions'
44

55
const options: MachineOptions<CR.MachineContext, CR.MachineEvent> = {
6-
// @ts-ignore
6+
activities: {},
77
actions,
8+
guards: {},
9+
services: {},
10+
delays: {},
811
}
912

1013
export const selectTutorialMachine = Machine<CR.MachineContext, CR.SelectTutorialMachineStateSchema, CR.MachineEvent>(
@@ -42,12 +45,31 @@ export const selectTutorialMachine = Machine<CR.MachineContext, CR.SelectTutoria
4245
},
4346
},
4447
SelectTutorial: {
45-
onEntry: ['clearStorage'],
46-
id: 'start-new-tutorial',
4748
on: {
48-
TUTORIAL_START: {
49+
SELECTED: 'Summary',
50+
},
51+
},
52+
Summary: {
53+
on: {
54+
BACK: 'SelectTutorial',
55+
LOAD_TUTORIAL: {
56+
target: 'Configure',
57+
actions: ['newTutorial', 'initTutorial'],
58+
},
59+
},
60+
},
61+
Configure: {
62+
onEntry: ['clearStorage, configureTutorial'],
63+
on: {
64+
TUTORIAL_CONFIGURED: 'Launch',
65+
// TUTORIAL_CONFIG_ERROR: 'Start' // TODO should handle error
66+
},
67+
},
68+
Launch: {
69+
// awaits tutorial configuration
70+
on: {
71+
LOAD_TUTORIAL: {
4972
type: 'final',
50-
actions: ['newTutorial'],
5173
},
5274
},
5375
},

0 commit comments

Comments
 (0)