8000 clean up typings preventing build · jordanliu/coderoad-vscode@f73bfcb · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f73bfcb

Browse files
committed
clean up typings preventing build
1 parent adb575b commit f73bfcb

File tree

13 files changed

+164
-101
lines changed

13 files changed

+164
-101
lines changed

src/editor/commands/index.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,16 @@ export const createCommands = ({vscodeExt}: CreateCommandProps) => {
117117
// machine.send(action)
118118
},
119119
[COMMANDS.RUN_TEST]: () => {
120-
// runTest({
121-
// onSuccess: () => machine.send('TEST_PASS'),
122-
// onFail: () => machine.send('TEST_FAIL'),
123-
// })
124-
},
125-
[COMMANDS.TEST_PASS]: () => {
126-
vscode.window.showInformationMessage('PASS')
127-
},
128-
[COMMANDS.TEST_FAIL]: () => {
129-
vscode.window.showWarningMessage('FAIL')
120+
runTest({
121+
onSuccess: () => {
122+
console.log('TEST_PASS')
123+
vscode.window.showInformationMessage('PASS')
124+
},
125+
onFail: () => {
126+
console.log('TEST_FAIL')
127+
vscode.window.showWarningMessage('FAIL')
128+
}
129+
})
130130
},
131131
}
132132
}

src/editor/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as vscode from 'vscode'
2-
import {setWorkspaceRoot} from './services/node'
2+
import {setWorkspaceRoot} from '../services/node'
33
import {createCommands} from './commands'
44

55
class Editor {

src/services/tutorial/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class Tutorial implements TutorialModel {
3838
}
3939
public launch = async (tutorial: G.Tutorial) => {
4040
console.log('launch tutorial')
41-
machine.send('TUTORIAL_START')
41+
// machine.send('TUTORIAL_START')
4242

4343
console.log('tutorial', tutorial)
4444

typings/index.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {send} from 'xstate'
22
import TutorialModel from '../src/services/tutorial'
3+
import * as G from './graphql'
34

45
export interface TutorialLevel {
56
stageList: string[]
@@ -116,8 +117,8 @@ export interface Action {
116117

117118
export interface MachineContext {
118119
tutorial: G.Tutorial | null,
119-
position: CR.Position,
120-
progress: CR.Progress,
120+
position: Position,
121+
progress: Progress,
121122
}
122123

123124
export interface MachineEvent {

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

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,33 @@ import Route from './Route'
77
import debuggerWrapper from '../Debugger/debuggerWrapper'
88
import channel from '../../services/channel'
99
import messageBusReceiver from '../../services/channel/receiver'
10-
import actions from '../../services/state/actions'
11-
1210

1311
interface Props {
1412
children: any
1513
}
1614

1715
interface CloneElementProps {
18-
context: CR.MachineContext
19-
send(action: CR.Action): void
16+
context: CR.MachineContext
17+
send(action: CR.Action): void
2018
}
2119

2220
// router finds first state match of <Route path='' />
23-
const Router = ({ children }: Props): React.ReactElement<CloneElementProps>|null => {
24-
const [state, send] = useMachine(machine, {
25-
actions,
26-
interpreterOptions: {
27-
logger: console.log.bind('XSTATE:')
28-
}
29-
})
21+
const Router = ({ children }: Props): React.ReactElement<CloneElementProps> | null => {
22+
const [state, send] = useMachine(machine, {
23+
interpreterOptions: {
24+
logger: console.log.bind('XSTATE:'),
25+
},
26+
})
3027

31-
channel.setMachineSend(send)
28+
channel.setMachineSend(send)
3229

33-
// event bus listener
30+
// event bus listener
3431
React.useEffect(messageBusReceiver, [])
3532

3633
const childArray = React.Children.toArray(children)
3734
for (const child of childArray) {
3835
if (state.matches(child.props.path)) {
39-
const element = React.cloneElement<CloneElementProps>(child.props.children, { send, context: state.context })
36+
const element = React.cloneElement<CloneElementProps>(child.props.children, { send, context: state.context })
4037
return debuggerWrapper(element, state)
4138
}
4239
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@ interface ContainerProps {
2727
}
2828

2929
const ContinuePageContainer = ({ context, send }: ContainerProps) => {
30-
// TODO: load specific tutorialId
3130
const { tutorial } = context
3231

32+
if (!tutorial) {
33+
throw new Error('Tutorial not found')
34+
}
35+
3336
return <ContinuePage tutorial={tutorial} onContinue={() => send('TUTORIAL_START')} />
3437
}
3538

web-app/src/containers/Tutorial/LevelPage/index.tsx

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,36 @@ export const LevelSummaryPage = (props: LevelProps) => {
1313
const onNext = (): void => {
1414
props.send('NEXT')
1515
}
16-
return <Level level={props.level} onNext={onNext} />
16+
return <Level level={props.level} onNext={onNext} />
1717
}
1818

1919
interface ContainerProps {
20-
context: CR.MachineContext
21-
send(action: string): void
20+
context: CR.MachineContext
21+
send(action: string): void
2222
}
2323

2424
const LevelSummaryPageContainer = (props: ContainerProps) => {
25-
const { tutorial, position, progress } = props.context
26-
27-
const level: G.Level = tutorial.version.levels.find((l: G.Level) => l.id === position.levelId)
28-
29-
level.stages.forEach((stage: G.Stage) => {
30-
if (stage.id === position.stageId) {
31-
stage.status = 'ACTIVE'
32-
} else if (progress.stages[stage.id]) {
33-
stage.status = 'COMPLETE'
34-
} else {
35-
stage.status = 'INCOMPLETE'
36-
}
37-
})
25+
const { tutorial, position, progress } = props.context
26+
27+
if (!tutorial) {
28+
throw new Error('Tutorial not found in LevelSummaryPageContainer')
29+
}
30+
31+
const level: G.Level | undefined = tutorial.version.levels.find((l: G.Level) => l.id === position.levelId)
32+
33+
if (!level) {
34+
throw new Error('Level not found in LevelSummaryPageContainer')
35+
}
36+
37+
level.stages.forEach((stage: G.Stage) => {
38+
if (stage.id === position.stageId) {
39+
stage.status = 'ACTIVE'
40+
} else if (progress.stages[stage.id]) {
41+
stage.status = 'COMPLETE'
42+
} else {
43+
stage.status = 'INCOMPLETE'
44+
}
45+
})
3846

3947
return <LevelSummaryPage level={level} send={props.send} />
4048
}

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

Lines changed: 46 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,47 +5,59 @@ import * as G from 'typings/graphql'
55
import Stage from './Stage'
66

77
interface PageProps {
8-
context: CR.MachineContext
8+
context: CR.MachineContext
99
send(action: CR.Action): void
1010
}
1111

1212
const StageSummaryPageContainer = (props: PageProps) => {
13-
const { tutorial, position, progress } = props.context
13+
const { tutorial, position, progress } = props.context
14+
15+
if (!tutorial) {
16+
throw new Error('Tutorial not found in StageSummaryPageContainer')
17+
}
18+
19+
const level: G.Level | undefined = tutorial.version.levels.find((l: G.Level) => l.id === position.levelId)
20+
21+
if (!level) {
22+
throw new Error('Level not found in StageSummaryPageContainer')
23+
}
24+
25+
const stage: G.Stage | undefined = level.stages.find((s: G.Stage) => s.id === position.stageId)
26+
27+
if (!stage) {
28+
throw new Error('Stage not found in StageSummaryPageContainer')
29+
}
1430

15-
const stage: G.Stage = tutorial.version
16-
.levels.find((l: G.Level) => l.id === position.levelId)
17-
.stages.find((s: G.Stage) => s.id === position.stageId)
18-
1931
const onContinue = (): void => {
2032
props.send({
21-
type: 'STAGE_NEXT',
22-
payload: {
23-
stageId: position.stageId,
24-
}
25-
})
26-
}
27-
28-
const onSave =(): void => {
29-
props.send({
30-
type: 'TEST_RUN',
31-
payload: {
32-
stepId: position.stepId,
33-
}
34-
})
35-
}
36-
37-
stage.steps.forEach((step: G.Step) => {
38-
if (progress.steps[step.id]) {
39-
step.status = 'COMPLETE'
40-
} else if (step.id === position.stepId) {
41-
step.status = 'ACTIVE'
42-
} else {
43-
step.status = 'INCOMPLETE'
44-
}
45-
})
46-
stage.status = progress.stages[position.stageId] ? 'COMPLETE' : 'ACTIVE'
47-
48-
return <Stage stage={stage} onContinue={onContinue} onSave={onSave}/>
33+
type: 'STAGE_NEXT',
34+
payload: {
35+
stageId: position.stageId,
36+
},
37+
})
38+
}
39+
40+
const onSave = (): void => {
41+
props.send({
42+
type: 'TEST_RUN',
43+
payload: {
44+
stepId: position.stepId,
45+
},
46+
})
47+
}
48+
49+
stage.steps.forEach((step: G.Step) => {
50+
if (progress.steps[step.id]) {
51+
step.status = 'COMPLETE'
52+
} else if (step.id === position.stepId) {
53+
step.status = 'ACTIVE'
54+
} else {
55+
step.status = 'INCOMPLETE'
56+
}
57+
})
58+
stage.status = progress.stages[position.stageId] ? 'COMPLETE' : 'ACTIVE'
59+
60+
return <Stage stage={stage} onContinue={onContinue} onSave={onSave} />
4961
}
5062

5163
export default StageSummaryPageContainer

web-app/src/containers/Tutorial/SummaryPage/index.tsx

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,21 @@ import Summary from './Summary'
77
import ErrorView from '../../../components/Error'
88

99
interface PageProps {
10-
context: CR.MachineContext
11-
send(action: CR.Action): void
10+
context: CR.MachineContext
11+
send(action: CR.Action): void
1212
}
1313

1414
const SummaryPage = (props: PageProps) => {
15-
const { tutorial } = props.context
15+
const { tutorial } = props.context
16+
17+
if (!tutorial) {
18+
throw new Error('Tutorial not found in summary page')
19+
}
1620
const { loading, error, data } = useQuery(queryTutorial, {
17-
fetchPolicy: 'network-only', // for debugging purposes
21+
fetchPolicy: 'network-only', // for debugging purposes
1822
variables: {
19-
tutorialId: tutorial.id,
20-
version: tutorial.version.version,
23+
tutorialId: tutorial.id,
24+
version: tutorial.version.version,
2125
},
2226
})
2327

@@ -29,14 +33,15 @@ const SummaryPage = (props: PageProps) => {
2933
return <ErrorView error={error} />
3034
}
3135

32-
const onNext = () => props.send({
33-
type: 'LOAD_TUTORIAL',
34-
payload: {
35-
tutorial: data.tutorial,
36-
}
37-
})
36+
const onNext = () =>
37+
props.send({
38+
type: 'LOAD_TUTORIAL',
39+
payload: {
40+
tutorial: data.tutorial,
41+
},
42+
})
3843

39-
const { title, text } = data.tutorial
44+
const { title, text } = data.tutorial
4045

4146
return <Summary title={title} text={text} onNext={onNext} />
4247
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ class Channel {
4141
this.machineSend(action)
4242
console.log('test passed')
4343
return
44+
case 'TEST_FAIL':
45+
this.machineSend(action)
46+
return
47+
case 'ACTIONS_LOADED':
48+
console.log('ACTIONS_LOADED')
49+
return
4450
default:
4551
if (action.type) {
4652
console.warn(`Unknown received action ${action.type}`, action)

0 commit comments

Comments
 (0)
0