Skip to content

Commit 04653e2

Browse files
committed
setup tutorial initialization
1 parent 6993147 commit 04653e2

File tree

4 files changed

+23
-15
lines changed

4 files changed

+23
-15
lines changed

src/state/actions/index.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ let initialProgress: CR.Progress = {
1313

1414
export default {
1515
start: async () => {
16+
// verify that the user has a tutorial & progress
17+
// verify git is setup with a coderoad remote
1618
const [tutorial, progress, hasGit, hasGitRemote] = await Promise.all([
1719
storage.getTutorial(),
1820
storage.getProgress(),
@@ -22,9 +24,11 @@ export default {
2224
initialTutorial = tutorial
2325
initialProgress = progress
2426
const canContinue = !!(tutorial && progress && hasGit && hasGitRemote)
27+
// if a tutorial exists, "CONTINUE"
28+
// otherwise start from "NEW"
2529
send(canContinue ? 'CONTINUE' : 'NEW')
2630
},
27-
loadTutorial: assign({
31+
tutorialLoad: assign({
2832
// load initial data, progress & position
2933
data(): CR.TutorialData {
3034
if (!initialTutorial) {
@@ -33,7 +37,9 @@ export default {
3337
return initialTutorial.data
3438

3539
},
36-
progress(): CR.Progress { return initialProgress },
40+
progress(): CR.Progress {
41+
return initialProgress
42+
},
3743
position() {
3844
if (!initialTutorial) {
3945
throw new Error('No Tutorial loaded')
@@ -53,4 +59,5 @@ export default {
5359
return position
5460
}
5561
}),
62+
5663
}

src/state/guards/index.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
import * as CR from 'typings'
12

23
export default {
3-
4+
// skip to the stage if the level has already been started
5+
hasNoNextLevelProgress: (context: CR.MachineContext): boolean => {
6+
return false
7+
},
48
}

src/state/machine.ts

+8-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Machine } from 'xstate'
1+
import { Machine, send } from 'xstate'
22
import * as CR from 'typings'
33

44
import actions from './actions'
@@ -43,28 +43,25 @@ export const tutorialMachine = Machine<
4343

4444
},
4545
ContinueTutorial: {
46-
onEntry: 'loadTutorial',
46+
onEntry: 'tutorialLoad',
4747
on: {
4848
TUTORIAL_START: {
49-
target: 'Tutorial',
49+
target: 'Tutorial.LoadNext',
5050
}
5151
}
5252
},
5353
}
5454
},
5555
Tutorial: {
56-
initial: 'Initialize',
56+
initial: 'Summary',
5757
states: {
58-
Initialize: {
58+
LoadNext: {
59+
onEntry: () => send('LOAD_NEXT'),
5960
on: {
60-
TUTORIAL_LOADED: [
61-
{
62-
target: 'Summary',
63-
cond: 'hasNoProgress',
64-
},
61+
LOAD_NEXT: [
6562
{
6663
target: 'Level',
67-
cond: 'hasNoLevelProgress',
64+
cond: 'hasNoNextLevelProgress',
6865
},
6966
{
7067
target: 'Stage',

src/typings/index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ export interface MachineStateSchema {
143143
}
144144
Tutorial: {
145145
states: {
146-
Initialize: {}
146+
LoadNext: {}
147147
Summary: {}
148148
Level: {}
149149
Stage: {

0 commit comments

Comments
 (0)