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

Commitbe46fad

Browse files
committed
create setStatus mutation
1 parent24eb6a6 commitbe46fad

File tree

7 files changed

+102
-89
lines changed

7 files changed

+102
-89
lines changed

‎web-app/src/App.tsx

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,41 @@
11
import*asReactfrom'react'
2-
import{ApolloProvider}from'@apollo/react-hooks'
2+
import{ApolloProvider,useMutation}from'@apollo/react-hooks'
33
import*asCRfrom'typings'
44

55
importclientfrom'./services/apollo'
6+
import{SET_STATUS}from'./services/apollo/mutations'
67
importDebuggerfrom'./components/Debugger'
78
importRoutesfrom'./Routes'
8-
importDataContext,{initialData,initialState}from'./utils/DataContext'
99
import{send}from'./utils/vscode'
1010

1111
interfaceReceivedEvent{
1212
data:CR.Action
1313
}
1414

1515
constApp=()=>{
16+
constinitialState={SelectTutorial:'Initial '}
17+
18+
// set state machine state
1619
const[state,setState]=React.useState(initialState)
17-
const[data,setData]:[CR.MachineContext,(data:CR.MachineContext)=>void]=React.useState(initialData)
20+
21+
// update level/stage/step status based on user progress & position
22+
// TODO: model server more effeciently
23+
const[setStatus]=useMutation(SET_STATUS)
1824

1925
// update state based on response from editor
2026
consthandleEvent=(event:ReceivedEvent):void=>{
2127
constmessage=event.data
2228
// messages from core
29+
const{ progress, position}=message.payload.data
30+
2331
if(message.type==='SET_STATE'){
32+
// SET_STATE - set state machine state
2433
setState(message.payload.state)
25-
setData(message.payload.data)
34+
35+
setStatus({variables:{ progress, position}})
2636
}elseif(message.type==='SET_DATA'){
27-
setData(message.payload.data)
37+
// SET_DATA - set state machine context
38+
setStatus({variables:{ progress, position}})
2839
}
2940
}
3041

@@ -44,20 +55,15 @@ const App = () => {
4455

4556
constvalue={
4657
state,
47-
position:data.position,
48-
data:data.data,
49-
progress:data.progress,
5058
}
5159

5260
// TODO: refactor cond to user <Router><Route> and accept first route as if/else if
5361
return(
5462
<ApolloProviderclient={client}>
55-
<DataContext.Providervalue={value}>
56-
<div>
57-
{process.env.REACT_APP_DEBUG&&<Debuggervalue={value}/>}
58-
<Routesstate={state}/>
59-
</div>
60-
</DataContext.Provider>
63+
<div>
64+
{process.env.REACT_APP_DEBUG&&<Debuggervalue={value}/>}
65+
<Routesstate={state}/>
66+
</div>
6167
</ApolloProvider>
6268
)
6369
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ const TutorialList = (props: Props) => (
1414
<TutorialItem
1515
key={tutorial.id}
1616
onNew={()=>props.onNew(tutorial.id)}
17-
title={tutorial.title}
18-
text={tutorial.text}
17+
title={tutorial.title||''}
18+
text={tutorial.text||''}
1919
/>
2020
))}
2121
</div>

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

Lines changed: 5 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,16 @@
11
importApolloClient,{InMemoryCache}from'apollo-boost'
22

3+
importtypeDefsfrom'./typeDefs'
4+
importresolversfrom'./resolvers'
5+
36
constclient=newApolloClient({
47
uri:process.env.REACT_APP_GQL_URI,
58
headers:{
69
Authorization:process.env.GQL_AUTH_TOKEN,
710
},
811
cache:newInMemoryCache(),
9-
resolvers:{
10-
Mutation:{
11-
setStatus:(_root,variables,{ cache, getCacheKey})=>{
12-
// TODO: optimize status setting to act on diffs
13-
14-
// set local cache
15-
functionset(typename:string,id:string,status:'ACTIVE'|'COMPLETE'){
16-
constwriteId=getCacheKey({__typename:typename, id})
17-
constdata={ status}
18-
cache.writeData({id:writeId, data})
19-
}
20-
21-
const{ progress, position}=variables
22-
23-
// set level progress & active
24-
for(constlevelIdofObject.keys(progress.levels)){
25-
set('Level',levelId,'COMPLETE')
26-
}
27-
set('Level',position.levelId,'ACTIVE')
28-
29-
// set stage progress & active
30-
for(conststageIdofObject.keys(progress.stages)){
31-
set('Stage',stageId,'COMPLETE')
32-
}
33-
set('Stage',position.stageId,'ACTIVE')
34-
35-
// set step progress & active
36-
for(conststepIdofObject.keys(progress.steps)){
37-
set('Step',stepId,'COMPLETE')
38-
}
39-
set('Step',position.stepId,'ACTIVE')
40-
41-
returnnull
42-
},
43-
},
44-
Level:{
45-
status(){
46-
return'INCOMPLETE'
47-
}
48-
},
49-
Stage:{
50-
status(){
51-
return'INCOMPLETE'
52-
}
53-
},
54-
Step:{
55-
status(){
56-
return'INCOMPLETE'
57-
}
58-
}
59-
},
12+
typeDefs,
13+
resolvers,
6014
})
6115

6216
exportdefaultclient
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import{gql}from'apollo-boost'
2+
3+
exportconstSET_STATUS=gql`
4+
mutation ToggleTodo($progress: Progress!, $position: Position) {
5+
setStatus(progress: $progress, position: $position) @client
6+
}
7+
`
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
constresolvers={
2+
Mutation:{
3+
setStatus:(_root,variables,{ cache, getCacheKey})=>{
4+
// TODO: optimize status setting to act on diffs
5+
6+
// set local cache
7+
functionset(typename:string,id:string,status:'ACTIVE'|'COMPLETE'){
8+
constwriteId=getCacheKey({__typename:typename, id})
9+
constdata={ status}
10+
cache.writeData({id:writeId, data})
11+
}
12+
13+
const{ progress, position}=variables
14+
15+
// set level progress & active
16+
for(constlevelIdofObject.keys(progress.levels)){
17+
set('Level',levelId,'COMPLETE')
18+
}
19+
set('Level',position.levelId,'ACTIVE')
20+
21+
// set stage progress & active
22+
for(conststageIdofObject.keys(progress.stages)){
23+
set('Stage',stageId,'COMPLETE')
24+
}
25+
set('Stage',position.stageId,'ACTIVE')
26+
27+
// set step progress & active
28+
for(conststepIdofObject.keys(progress.steps)){
29+
set('Step',stepId,'COMPLETE')
30+
}
31+
set('Step',position.stepId,'ACTIVE')
32+
33+
returnnull
34+
},
35+
},
36+
Level:{
37+
status(){
38+
return'INCOMPLETE'
39+
}
40+
},
41+
Stage:{
42+
status(){
43+
return'INCOMPLETE'
44+
}
45+
},
46+
Step:{
47+
status(){
48+
return'INCOMPLETE'
49+
}
50+
}
51+
}
52+
53+
exportdefaultresolvers
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import{gql}from'apollo-boost'
2+
3+
consttypeDefs=gql`
4+
input Progress {
5+
levels: JSONObject
6+
stages: JSONObject
7+
steps: JSONObject
8+
}
9+
input Position {
10+
levelId: String
11+
stageId: String
12+
stepId: String
13+
}
14+
`
15+
exportdefaulttypeDefs

‎web-app/src/utils/DataContext.tsx

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp