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

Commitcfbf955

Browse files
committed
fix loading of tutorial config on client
1 parent33eb7ff commitcfbf955

File tree

7 files changed

+44
-11
lines changed

7 files changed

+44
-11
lines changed

‎web-app/src/containers/New/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { useQuery } from '@apollo/react-hooks'
33
import*asTfrom'typings/graphql'
44
import*asCRfrom'typings'
55

6-
importqueryTutorialsfrom'./queryTutorials'
6+
importqueryTutorialsfrom'../../services/apollo/queries/tutorials'
77
importLoadingPagefrom'../LoadingPage'
88
importErrorViewfrom'../../components/Error'
99
importTutorialListfrom'./TutorialList'
@@ -22,7 +22,7 @@ export const NewPage = (props: Props) => (
2222
constLoading=()=><LoadingPagetext="Loading tutorials"/>
2323

2424
interfaceContainerProps{
25-
send(action:CR.Action):void
25+
send(action:CR.Action):void
2626
}
2727

2828
constNewPageContainer=(props:ContainerProps)=>{
@@ -33,11 +33,11 @@ const NewPageContainer = (props: ContainerProps) => {
3333

3434
if(error){
3535
return<ErrorViewerror={error}/>
36-
}
36+
}
3737

3838
return(
3939
<React.Suspensefallback={Loading}>
40-
<NewPagetutorialList={data.tutorials}/>
40+
<NewPagetutorialList={data.tutorials}/>
4141
</React.Suspense>
4242
)
4343
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as React from 'react'
22
import*asCRfrom'typings'
33
import{useQuery}from'@apollo/react-hooks'
44

5-
importqueryTutorialfrom'./queryTutorial'
5+
importqueryTutorialfrom'../../../services/apollo/queries/tutorial'
66
importSummaryfrom'./Summary'
77
importErrorViewfrom'../../../components/Error'
88

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import * as selectors from '../../selectors'
33
importchannelfrom'../../channel'
44

55
exportdefault{
6-
initializeTutorial(context:CR.MachineContext){
6+
initializeTutorial(context:CR.MachineContext,event:CR.MachineEvent){
77
// setup test runner and git
8-
const{tutorial}=context
8+
const{tutorial}=event.data.payload
99
if(!tutorial){
1010
thrownewError('Invalid tutorial for tutorial config')
1111
}

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import*asstoragefrom'../storage'
22
import*asCRfrom'typings'
33
import*asGfrom'typings/graphql'
4+
importclientfrom'../../apollo'
5+
importtutorialQueryfrom'../../apollo/queries/tutorial'
46

57
exportconstnewOrContinue=async(context:CR.MachineContext)=>{
68
const[tutorial,progress]=awaitPromise.all([
@@ -50,4 +52,30 @@ export const newOrContinue = async (context: CR.MachineContext) => {
5052
progress
5153
}
5254
}
55+
}
56+
57+
exportconstloadTutorial=async(context:CR.MachineContext)=>{
58+
if(!context.tutorial){
59+
thrownewError('Tutorial not available to load')
60+
}
61+
62+
constresult=awaitclient.query({
63+
query:tutorialQuery,
64+
variables:{
65+
tutorialId:context.tutorial.id,
66+
version:context.tutorial.version.version,
67+
}
68+
})
69+
.catch((error:Error)=>{
70+
returnPromise.reject(`Failed to load tutorial config${error.message}`)
71+
})
72+
if(!result||!result.data){
73+
returnPromise.reject('No tutorial returned from tutorial config query')
74+
}
75+
76+
const{data}=result
77+
return{
78+
type:'TUTORIAL_LOADED',
79+
payload:data
80+
}
5381
}

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,14 @@ export const machine = Machine<CR.MachineContext, CR.MachineStateSchema, CR.Mach
5858
initial:'Initialize',
5959
states:{
6060
Initialize:{
61-
onEntry:['initializeTutorial'],
62-
after:{
63-
0:'Summary',
61+
invoke:{
62+
id:'loadTutorial',
63+
src:invoke.loadTutorial,
64+
onDone:{
65+
target:'Summary',
66+
actions:['initializeTutorial']
67+
},
68+
onError:'Initialize'// TODO: handle load tutorial error
6469
},
6570
},
6671
LoadNext:{
@@ -87,7 +92,7 @@ export const machine = Machine<CR.MachineContext, CR.MachineStateSchema, CR.Mach
8792
on:{
8893
LOAD_TUTORIAL:{
8994
target:'Level',
90-
actions:['tutorialConfig','initPosition','setTutorial']
95+
actions:['initPosition','setTutorial']
9196
}
9297
},
9398
},

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp