Skip to content

Fix/state machine #97

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 8 commits into from
Feb 1, 2020
Prev Previous commit
Next Next commit
move init & summary into start
  • Loading branch information
ShMcK committed Jan 31, 2020
commit 1091125fe68391b2f3a34fc940ff13b54491bb53
5 changes: 2 additions & 3 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,14 @@ export interface MachineStateSchema {
Error: {}
NewOrContinue: {}
SelectTutorial: {}
LoadTutorial: {}
Summary: {}
ContinueTutorial: {}
}
}
Tutorial: {
states: {
Initialize: {}
Summary: {}
LoadNext: {}
Error: {}
Level: {
states: {
Load: {}
Expand Down
16 changes: 6 additions & 10 deletions web-app/src/Routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ import LevelSummaryPage from './containers/Tutorial/LevelPage'

const Routes = () => {
const { context, send, Router, Route } = useRouter()
// TODO refactor for typescript to understand send & context passed into React.cloneElement's
return (
<Workspace>
<Router>
<Route path={['Start.Startup', 'Start.Authenticate', 'Start.NewOrContinue']}>
<LoadingPage text="Launching..." context={context} />
</Route>
<Route path="Start.Initialize">
<LoadingPage text="Initializing..." context={context} />
</Route>
<Route path={'Start.Error'}>
<div>Something went wrong wrong</div>
</Route>
Expand All @@ -27,17 +29,11 @@ const Routes = () => {
<Route path="Start.ContinueTutorial">
<ContinuePage send={send} context={context} />
</Route>
<Route path={'Tutorial.Error'}>
<div>Something went wrong wrong</div>
</Route>
<Route path="Tutorial.Initialize">
<LoadingPage text="Initializing..." context={context} />
<Route path="Start.Summary">
<OverviewPage send={send} context={context} />
</Route>
<Route path="Tutorial.LoadNext">
<LoadingPage text="Loading..." context={context} />
</Route>
<Route path="Tutorial.Summary">
<OverviewPage send={send} context={context} />
<LoadingPage text="Loading Level..." context={context} />
</Route>
<Route path="Tutorial.Level">
<LevelSummaryPage send={send} context={context} />
Expand Down
1 change: 1 addition & 0 deletions web-app/src/components/Router/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const useRouter = () => {
const childArray = React.Children.toArray(children)
for (const child of childArray) {
// match path
// @ts-ignore
const { path } = child.props
let pathMatch
if (typeof path === 'string') {
Expand Down
62 changes: 30 additions & 32 deletions web-app/src/services/state/machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,46 @@ export const createMachine = (options: any) => {
target: 'ContinueTutorial',
actions: ['continueTutorial'],
},
NEW_TUTORIAL: {
target: 'SelectTutorial',
},
NEW_TUTORIAL: 'SelectTutorial',
},
},
SelectTutorial: {
onEntry: ['clearStorage'],
id: 'start-new-tutorial',
on: {
TUTORIAL_START: {
target: '#tutorial',
target: 'LoadTutorial',
actions: ['newTutorial'],
},
},
},
// TODO move Initialize into New Tutorial setup
LoadTutorial: {
invoke: {
src: services.loadTutorial,
onDone: {
target: 'Summary',
actions: assign({
tutorial: (context, event) => event.data,
}),
},
onError: {
target: 'Error',
actions: assign({
error: (context, event) => event.data,
}),
},
},
},
Summary: {
on: {
BACK: 'SelectTutorial',
LOAD_TUTORIAL: {
target: '#tutorial',
actions: ['initPosition', 'initTutorial'],
},
},
},
ContinueTutorial: {
on: {
TUTORIAL_START: {
Expand All @@ -95,7 +120,7 @@ export const createMachine = (options: any) => {
},
Tutorial: {
id: 'tutorial',
initial: 'Initialize',
initial: 'LoadNext',
on: {
// track commands
COMMAND_START: {
Expand All @@ -112,33 +137,6 @@ export const createMachine = (options: any) => {
},
},
states: {
// TODO move Initialize into New Tutorial setup
Initialize: {
invoke: {
src: services.initialize,
onDone: {
target: 'Summary',
actions: assign({
tutorial: (context, event) => event.data,
}),
},
onError: {
target: 'Error',
actions: assign({
error: (context, event) => event.data,
}),
},
},
},
Error: {},
Summary: {
on: {
LOAD_TUTORIAL: {
target: 'Level',
actions: ['initPosition', 'initTutorial'],
},
},
},
LoadNext: {
id: 'tutorial-load-next',
onEntry: ['loadNext'],
Expand Down
2 changes: 1 addition & 1 deletion web-app/src/services/state/services/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { authenticate } from './authenticate'
export { initialize } from './initialize'
export { loadTutorial } from './loadTutorial'
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface TutorialDataVariables {
// version: string
}

export async function initialize(context: CR.MachineContext): Promise<any> {
export async function loadTutorial(context: CR.MachineContext): Promise<any> {
// setup test runner and git
if (!context.tutorial) {
const error = new Error('Tutorial not available to load')
Expand Down