Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commitda942ac

Browse files
committed
cleanup hasNext guards
1 parente0e2839 commitda942ac

File tree

9 files changed

+63
-121
lines changed

9 files changed

+63
-121
lines changed

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

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
import*asReactfrom'react'
2-
import{useQuery}from'@apollo/react-hooks'
32
import*asCRfrom'typings'
43
import*asGfrom'typings/graphql'
54

6-
importErrorViewfrom'../../../components/Error'
75
importLevelfrom'./Level'
8-
importqueryLevelfrom'./queryLevel'
96

107
interfaceLevelProps{
118
level:G.Level
@@ -30,23 +27,7 @@ interface ContainerProps {
3027
constLevelSummaryPageContainer=(props:ContainerProps)=>{
3128
const{ tutorial, position, progress}=props.context
3229

33-
const{ loading, error, data}=useQuery(queryLevel,{
34-
variables:{
35-
tutorialId:tutorial.id,
36-
version:tutorial.version.version,
37-
levelId:position.levelId,
38-
},
39-
})
40-
41-
if(loading){
42-
return<div>Loading Levels...</div>
43-
}
44-
45-
if(error){
46-
return<ErrorViewerror={error}/>
47-
}
48-
49-
const{ level}=data.tutorial.version
30+
constlevel:G.Level=tutorial.version.levels.find((l:G.Level)=>l.id===position.levelId)
5031

5132
level.stages.forEach((stage:G.Stage)=>{
5233
if(stage.id===position.stageId){

‎web-app/src/containers/Tutorial/LevelPage/queryLevel.ts

Lines changed: 0 additions & 35 deletions
This file was deleted.

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

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
import*asReactfrom'react'
22
import*asCRfrom'typings'
33
import*asGfrom'typings/graphql'
4-
import{useQuery}from'@apollo/react-hooks'
54

6-
importErrorViewfrom'../../../components/Error'
75
importStagefrom'./Stage'
8-
importqueryStagefrom'./queryStage'
96

107
interfacePageProps{
118
context:CR.MachineContext,
@@ -14,22 +11,8 @@ interface PageProps {
1411

1512
constStageSummaryPageContainer=(props:PageProps)=>{
1613
const{ tutorial, position, progress}=props.context
17-
const{ loading, error, data}=useQuery(queryStage,{
18-
variables:{
19-
tutorialId:tutorial.id,
20-
version:tutorial.version.version,
21-
stageId:position.stageId,
22-
},
23-
})
24-
if(loading){
25-
return<div>Loading Stage...</div>
26-
}
2714

28-
if(error){
29-
return<ErrorViewerror={error}/>
30-
}
31-
32-
const{ stage}=data.tutorial.version
15+
conststage:G.Stage=tutorial.version.levels.find((l:G.Level)=>l.id===position.levelId).stages.find((s:G.Stage)=>s.id===position.stageId)
3316

3417
constonContinue=():void=>{
3518
props.send({
@@ -42,7 +25,7 @@ const StageSummaryPageContainer = (props: PageProps) => {
4225

4326
constonSave=():void=>{
4427
props.send({
45-
type:'TEST_RUNNING',
28+
type:'TEST_RUN',
4629
payload:{
4730
stepId:position.stepId,
4831
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ class Channel {
3838
this.machineSend('TUTORIAL_LOADED')
3939
console.log('send action to state machine')
4040
return
41+
case'TEST_PASS':
42+
this.machineSend(action)
43+
console.log('test passed')
44+
return
4145
default:
4246
console.warn(`Unknown received action${action.type}`,action)
4347
}

‎web-app/src/services/channel/mock.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ window.acquireVsCodeApi = () => ({
1919
}
2020
channel.receive(createReceiveEvent(receiveAction))
2121
},1000)
22+
case'TEST_RUN':
23+
returnsetTimeout(()=>{
24+
constreceiveAction:Action={
25+
type:'TEST_PASS',
26+
payload:action.payload,
27+
}
28+
channel.receive(createReceiveEvent(receiveAction))
29+
})
2230
default:
2331
console.warn(`${action.type} not found in post message mock`)
2432
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@ export default {
2727
},
2828
}),
2929
//@ts-ignore
30-
testPass:assign({
30+
updateStepProgress:assign({
3131
progress:(context:CR.MachineContext,event:CR.MachineEvent):CR.Progress=>{
3232
// update progress by tracking completed
3333
constcurrentProgress:CR.Progress=context.progress
34+
console.log('progress update',event.payload)
3435
conststepId=event.payload.stepId
3536

3637
currentProgress.steps[stepId]=true
@@ -44,9 +45,10 @@ export default {
4445
constcurrentPosition:CR.Position=context.position
4546
// merge in the updated position
4647
// sent with the test to ensure consistency
48+
console.log('should calculate next step')
49+
4750
return{
4851
...currentPosition,
49-
...event.payload.nextPosition,
5052
}
5153
},
5254
})

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,14 @@ export default {
1515
testRunnerSetup(context:CR.MachineContext){
1616
console.log('test runner setup',context)
1717
},
18-
testStart(){
18+
testStart(context:CR.MachineContext,event:CR.MachineEvent){
1919
console.log('test start')
20+
const{stepId}=event.payload
21+
channel.editorSend({
22+
type:'TEST_RUN',
23+
payload:{
24+
stepId,
25+
}
26+
})
2027
}
2128
}
Lines changed: 28 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,30 @@
1-
// import * as CR from 'typings'
2-
// import {TutorialModel} from '../../services/tutorial'
3-
4-
5-
exportdefault{}
1+
import*asGfrom'typings/graphql'
2+
import*asCRfrom'typings'
63

74
// // TODO: refactor into a single calculation
8-
// export default (tutorialModel: TutorialModel) => ({
9-
// hasNextStep: (): boolean => {
10-
11-
// const nextPosition: CR.Position = tutorialModel.nextPosition()
12-
13-
// const sameStage = nextPosition.stageId === tutorialModel.position.stageId
14-
// const sameStep = nextPosition.stepId === tutorialModel.position.stepId
15-
16-
// const hasNext: boolean = sameStage && sameStep
17-
18-
// console.log('GUARD: hasNextStep', hasNext)
19-
// return hasNext
20-
// },
21-
// hasNextStage: (): boolean => {
22-
// const nextPosition: CR.Position = tutorialModel.nextPosition()
23-
24-
// const sameLevel = nextPosition.levelId === tutorialModel.position.levelId
25-
// const sameStage = nextPosition.stageId === tutorialModel.position.stageId
26-
27-
// const hasNext: boolean = sameLevel && sameStage
28-
29-
// console.log('GUARD: hasNextStage', hasNext)
30-
// return hasNext
31-
// },
32-
// hasNextLevel: (): boolean => {
33-
// const nextPosition: CR.Position = tutorialModel.nextPosition()
34-
35-
// const sameLevel = nextPosition.levelId === tutorialModel.position.levelId
36-
37-
// const hasNext: boolean = sameLevel
38-
39-
// // TODO: ensure this accounts for end
40-
// console.log('GUARD: hasNextLevel', hasNext)
41-
// return hasNext
42-
// },
43-
// })
5+
exportdefault{
6+
hasNextStep:(context:CR.MachineContext):boolean=>{
7+
const{tutorial, position}=context
8+
// TODO: protect against errors
9+
conststeps:G.Step[]=tutorial.version.levels.find((l:G.Level)=>l.id===position.levelId).stages.find((s:G.Stage)=>s.id===position.stageId).steps
10+
11+
// TODO: verify not -1
12+
return!(steps.indexOf(position.stepId)===steps.length-1)
13+
},
14+
hasNextStage:(context:CR.MachineContext):boolean=>{
15+
const{tutorial, position}=context
16+
// TODO: protect against errors
17+
conststages:G.Stage[]=tutorial.version.levels.find((l:G.Level)=>l.id===position.levelId).stages
18+
19+
// TODO: verify not -1
20+
return!(stages.indexOf(position.stageId)===stages.length-1)
21+
},
22+
hasNextLevel:(context:CR.MachineContext):boolean=>{
23+
const{tutorial, position}=context
24+
// TODO: protect against errors
25+
constlevels:G.Level[]=tutorial.version.levels
26+
27+
// TODO: verify not -1
28+
return!(levels.indexOf(position.levelId)===levels.length-1)
29+
},
30+
}

‎web-app/src/services/state/machine.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,10 @@ export const machine = Machine<CR.MachineContext, CR.MachineStateSchema, CR.Mach
110110
states:{
111111
Normal:{
112112
on:{
113-
TEST_RUN:'TestRunning',
113+
TEST_RUN:{
114+
target:'TestRunning',
115+
actions:'testStart',
116+
},
114117
STEP_SOLUTION_LOAD:{
115118
actions:['callSolution'],
116119
},
@@ -119,12 +122,14 @@ export const machine = Machine<CR.MachineContext, CR.MachineStateSchema, CR.Mach
119122
TestRunning:{
120123
onEntry:['testStart'],
121124
on:{
122-
TEST_PASS:'TestPass',
125+
TEST_PASS:{
126+
target:'TestPass',
127+
actions:['updateStepProgress']
128+
},
123129
TEST_FAIL:'TestFail',
124130
},
125131
},
126132
TestPass:{
127-
onEntry:['testPass'],
128133
onExit:['stepLoadNext'],
129134
after:{
130135
1000:'StepNext',

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp