Skip to content

Commit df9de6e

Browse files
committed
fix crash on restart
1 parent 2d06aac commit df9de6e

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

src/services/position.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,4 @@ export async function loadProgressPosition() {
6262
storage.setPosition(position)
6363
}
6464

65-
export async function getPrev(): Promise<void> {}
65+
export async function getPrev(): Promise<void> { }

src/state/actions/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ export default (dispatch: CR.EditorDispatch) => ({
4747
},
4848
tutorialSetup() {
4949
dispatch('coderoad.tutorial_setup', currentTutorial)
50-
dispatch('coderoad.open_webview', 2)
5150
},
5251
initializeNewTutorial: assign({
5352
position: (context: any): CR.Position => {
@@ -88,6 +87,8 @@ export default (dispatch: CR.EditorDispatch) => ({
8887
const levelId = levelList.find((id: string) => !currentProgress.levels[id]) || levelList[levelList.length - 1]
8988
const { stageList } = data.levels[levelId]
9089
const stageId = stageList.find((id: string) => !currentProgress.stages[id]) || stageList[stageList.length - 1]
90+
console.log('position stepList')
91+
console.log(data.stages[stageId])
9192
const { stepList } = data.stages[stageId]
9293
const stepId = stepList.find((id: string) => !currentProgress.steps[id]) || stepList[stepList.length - 1]
9394

src/state/index.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ interface Props {
1212
class StateMachine {
1313
private dispatch: CR.EditorDispatch
1414
private machineOptions = {
15-
logger: console.log,
1615
devTools: true,
1716
deferEvents: true,
1817
execute: true,
@@ -24,10 +23,10 @@ class StateMachine {
2423
this.service = interpret(machine, this.machineOptions)
2524
// logging
2625
.onTransition(state => {
27-
console.log('onTransition', state)
26+
// console.log('onTransition', state)
2827
if (state.changed) {
29-
console.log('next state')
30-
console.log(state.value)
28+
// console.log('next state')
29+
// console.log(state.value)
3130
dispatch('coderoad.send_state', { state: state.value, data: state.context })
3231
} else {
3332
dispatch('coderoad.send_data', { data: state.context })
@@ -43,6 +42,7 @@ class StateMachine {
4342
}
4443
public refresh() {
4544
console.log('service refresh')
45+
console.log(this.service.state)
4646
const { value, context } = this.service.state
4747
this.dispatch('coderoad.send_state', { state: value, data: context })
4848
}

web-app/src/containers/Tutorial/StagePage.tsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,20 @@ import DataContext from '../../utils/DataContext'
33
import Stage from '../../components/Stage'
44

55
interface PageProps {
6-
send(action: string): void
76
state: any
7+
send(action: string): void
88
}
99

1010
const StagePage = (props: PageProps) => {
1111
const { position, data, progress } = React.useContext(DataContext)
1212
const { stageId } = position
1313
const stage = data.stages[stageId]
1414

15+
if (!stage) {
16+
// may throw if no stage is supplied on restart
17+
return <div>No Stage!</div>
18+
}
19+
1520
const stageComplete = progress.stages[stageId] || false
1621

1722
const onNextStage = (): void => {

0 commit comments

Comments
 (0)