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

Commit6869a22

Browse files
committed
add SetupNewTutorial state
1 parentd91b259 commit6869a22

File tree

11 files changed

+151
-42
lines changed

11 files changed

+151
-42
lines changed

‎typings/graphql.d.ts

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ export type MutationUpdateTutorialProgressArgs = {
137137
}
138138

139139
exporttypeMutationCreateTutorialArgs={
140-
input:CreateTutorialInput
140+
input:Scalars['String']
141141
}
142142

143143
exporttypeMutationCreateTutorialVersionArgs={
@@ -347,14 +347,14 @@ export type ResolversTypes = {
347347
TutorialProgressType:TutorialProgressType
348348
TutorialProgressStatus:TutorialProgressStatus
349349
Boolean:ResolverTypeWrapper<Scalars['Boolean']>
350-
createTutorialInput:CreateTutorialInput
351350
createTutorialVersionInput:CreateTutorialVersionInput
352351
updateTutorialVersionInput:UpdateTutorialVersionInput
353352
JSONObject:ResolverTypeWrapper<Scalars['JSONObject']>
354353
Sha1:ResolverTypeWrapper<Scalars['Sha1']>
355354
Role:Role
356355
FileFormat:FileFormat
357356
tutorialRepoInput:TutorialRepoInput
357+
createTutorialInput:CreateTutorialInput
358358
GithubUser:ResolverTypeWrapper<GithubUser>
359359
}
360360

@@ -380,14 +380,14 @@ export type ResolversParentTypes = {
380380
TutorialProgressType:TutorialProgressType
381381
TutorialProgressStatus:TutorialProgressStatus
382382
Boolean:Scalars['Boolean']
383-
createTutorialInput:CreateTutorialInput
384383
createTutorialVersionInput:CreateTutorialVersionInput
385384
updateTutorialVersionInput:UpdateTutorialVersionInput
386385
JSONObject:Scalars['JSONObject']
387386
Sha1:Scalars['Sha1']
388387
Role:Role
389388
FileFormat:FileFormat
390389
tutorialRepoInput:TutorialRepoInput
390+
createTutorialInput:CreateTutorialInput
391391
GithubUser:GithubUser
392392
}
393393

@@ -601,15 +601,3 @@ export type DirectiveResolvers<ContextType = any> = {
601601
* Use "DirectiveResolvers" root object instead. If you wish to get "IDirectiveResolvers", add "typesPrefix: I" to your config.
602602
*/
603603
exporttypeIDirectiveResolvers<ContextType=any>=DirectiveResolvers<ContextType>
604-
605-
exportinterfaceIntrospectionResultData{
606-
__schema:{
607-
types:{
608-
kind:string
609-
name:string
610-
possibleTypes:{
611-
name:string
612-
}[]
613-
}[]
614-
}
615-
}

‎typings/index.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,10 @@ export interface MachineStateSchema {
6666
Error:{}
6767
NewOrContinue:{}
6868
SelectTutorial:{}
69-
LoadTutorial:{}
69+
LoadTutorialSummary:{}
7070
Summary:{}
71+
LoadTutorialData:{}
72+
SetupNewTutorial:{}
7173
ContinueTutorial:{}
7274
}
7375
}

‎web-app/src/Routes.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import*asReactfrom'react'
2-
import*asCRfrom'typings'
32
importuseRouterfrom'./components/Router'
43
importWorkspacefrom'./components/Workspace'
54
importContinuePagefrom'./containers/Continue'
@@ -21,8 +20,8 @@ const Routes = () => {
2120
<Routepath="Start.ContinueTutorial">
2221
<ContinuePagesend={send}context={context}/>
2322
</Route>
24-
<Routepath="Start.Initialize">
25-
<LoadingPagetext="Initializing..."context={context}/>
23+
<Routepath={['Start.LoadTutorialSummary','Start.LoadTutorialData']}>
24+
<LoadingPagetext="Loading Tutorial..."context={context}/>
2625
</Route>
2726
<Routepath={'Start.Error'}>
2827
<LoadingPagetext="Error"context={context}/>
@@ -33,6 +32,9 @@ const Routes = () => {
3332
<Routepath="Start.Summary">
3433
<OverviewPagesend={send}context={context}/>
3534
</Route>
35+
<Routepath="SetupNewTutorial">
36+
<LoadingPagetext="Configuring tutorial..."context={context}/>
37+
</Route>
3638
{/* Tutorial */}
3739
<Routepath="Tutorial.LoadNext">
3840
<LoadingPagetext="Loading Level..."context={context}/>

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
import*asReactfrom'react'
2+
import*asTfrom'typings'
23
import{createMachine}from'../../services/state/machine'
34
import{useMachine}from'../../services/xstate-react'
45
importRoutefrom'./Route'
56
importonErrorfrom'../../services/sentry/onError'
67

7-
interfaceProps{
8-
children:any
8+
interfaceOutput{
9+
context:T.MachineContext
10+
send:(action:any)=>void
11+
Router:any
12+
Route:any
913
}
1014

1115
declareletacquireVsCodeApi:any
1216

1317
consteditor=acquireVsCodeApi()
1418

1519
// router finds first state match of <Route path='' />
16-
constuseRouter=()=>{
17-
const[state,send]=useMachine(createMachine({editorSend:editor.postMessage}))
20+
constuseRouter=():Output=>{
21+
const[state,send]=useMachine<T.MachineContext,any>(createMachine({editorSend:editor.postMessage}))
1822

1923
// event bus listener
2024
React.useEffect(()=>{
@@ -35,7 +39,7 @@ const useRouter = () => {
3539
}
3640
},[])
3741

38-
constRouter=({ children}:Props):React.ReactElement<any>|null=>{
42+
constRouter=({ children}:any)=>{
3943
constchildArray=React.Children.toArray(children)
4044
for(constchildofchildArray){
4145
// match path
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import{gql}from'apollo-boost'
2+
3+
// TODO: add version to query
4+
5+
exportdefaultgql`
6+
query getTutorial($tutorialId: ID!) {
7+
tutorial(id: $tutorialId) {
8+
id
9+
createdBy {
10+
id
11+
name
12+
email
13+
}
14+
summary {
15+
title
16+
description
17+
}
18+
version {
19+
id
20+
createdAt
21+
createdBy {
22+
id
23+
name
24+
}
25+
updatedAt
26+
updatedBy {
27+
id
28+
name
29+
}
30+
publishedAt
31+
publishedBy {
32+
name
33+
}
34+
data {
35+
levels {
36+
id
37+
title
38+
summary
39+
}
40+
}
41+
}
42+
}
43+
}
44+
`

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,10 @@ const contextActions: ActionFunctionMap<CR.MachineContext, CR.MachineEvent> = {
3636
},
3737
}),
3838
//@ts-ignore
39-
initTutorial:assign({
40-
// loads complete tutorial
41-
tutorial:(context:CR.MachineContext,event:CR.MachineEvent):any=>{
42-
returnevent.payload.tutorial
43-
},
44-
}),
45-
//@ts-ignore
4639
initPosition:assign({
4740
position:(context:CR.MachineContext,event:CR.MachineEvent):CR.Position=>{
48-
constposition:CR.Position=selectors.initialPosition(event.payload)
41+
console.log('init position')
42+
constposition:CR.Position=selectors.initialPosition(context)
4943
returnposition
5044
},
5145
}),

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ export default (editorSend: any) => ({
1515
type:'EDITOR_TUTORIAL_LOAD',
1616
})
1717
},
18+
configureNewTutorial(context:CR.MachineContext){
19+
editorSend({
20+
type:'EDITOR_TUTORIAL_CONFIG',
21+
payload:{
22+
// pass position because current stepId or first stepId will be empty
23+
tutorial:context.tutorial,
24+
},
25+
})
26+
},
1827
continueConfig(context:CR.MachineContext){
1928
editorSend({
2029
type:'EDITOR_TUTORIAL_CONTINUE_CONFIG',

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

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import*asCRfrom'typings'
2-
import{assign,Machine,MachineOptions,actions}from'xstate'
2+
import{assign,Machine,MachineOptions}from'xstate'
33
importeditorActionsfrom'./actions/editor'
44
importcommandActionsfrom'./actions/command'
55
importcontextActionsfrom'./actions/context'
@@ -72,18 +72,18 @@ export const createMachine = (options: any) => {
7272
},
7373
SelectTutorial:{
7474
onEntry:['clearStorage'],
75-
id:'start-new-tutorial',
75+
id:'select-new-tutorial',
7676
on:{
7777
SELECT_TUTORIAL:{
78-
target:'LoadTutorial',
78+
target:'LoadTutorialSummary',
7979
actions:['newTutorial'],
8080
},
8181
},
8282
},
8383
// TODO move Initialize into New Tutorial setup
84-
LoadTutorial:{
84+
LoadTutorialSummary:{
8585
invoke:{
86-
src:services.loadTutorial,
86+
src:services.loadTutorialSummary,
8787
onDone:{
8888
target:'Summary',
8989
actions:assign({
@@ -102,9 +102,31 @@ export const createMachine = (options: any) => {
102102
on:{
103103
BACK:'SelectTutorial',
104104
TUTORIAL_START:{
105-
target:'#tutorial',
106-
actions:['initPosition','initTutorial'],
105+
target:'LoadTutorialData',
106+
},
107+
},
108+
},
109+
LoadTutorialData:{
110+
invoke:{
111+
src:services.loadTutorialData,
112+
onDone:{
113+
target:'SetupNewTutorial',
114+
actions:assign({
115+
tutorial:(context,event)=>event.data,
116+
}),
107117
},
118+
onError:{
119+
target:'Error',
120+
actions:assign({
121+
error:(context,event)=>event.data,
122+
}),
123+
},
124+
},
125+
},
126+
SetupNewTutorial:{
127+
onEntry:['configureNewTutorial','initPosition'],
128+
after:{
129+
0:'#tutorial',
108130
},
109131
},
110132
ContinueTutorial:{
@@ -224,7 +246,7 @@ export const createMachine = (options: any) => {
224246
onEntry:['userTutorialComplete'],
225247
on:{
226248
SELECT_TUTORIAL:{
227-
target:'#start-new-tutorial',
249+
target:'#select-new-tutorial',
228250
actions:['reset'],
229251
},
230252
},
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export{authenticate}from'./authenticate'
2-
export{loadTutorial}from'./loadTutorial'
2+
export{loadTutorialData}from'./loadTutorialData'
3+
export{loadTutorialSummary}from'./loadTutorialSummary'

‎web-app/src/services/state/services/loadTutorial.tsrenamed to‎web-app/src/services/state/services/loadTutorialData.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ interface TutorialDataVariables {
1313
// version: string
1414
}
1515

16-
exportasyncfunctionloadTutorial(context:CR.MachineContext):Promise<any>{
16+
exportasyncfunctionloadTutorialData(context:CR.MachineContext):Promise<any>{
1717
// setup test runner and git
1818
if(!context.tutorial){
1919
consterror=newError('Tutorial not available to load')
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import*asCRfrom'typings'
2+
import*asGfrom'typings/graphql'
3+
importclientfrom'../../apollo'
4+
importsummaryQueryfrom'../../apollo/queries/summary'
5+
importonErrorfrom'../../../services/sentry/onError'
6+
7+
interfaceTutorialData{
8+
tutorial:G.Tutorial
9+
}
10+
11+
interfaceTutorialDataVariables{
12+
tutorialId:string
13+
// version: string
14+
}
15+
16+
exportasyncfunctionloadTutorialSummary(context:CR.MachineContext):Promise<any>{
17+
// setup test runner and git
18+
if(!context.tutorial){
19+
consterror=newError('Tutorial not available to load')
20+
onError(error)
21+
throwerror
22+
}
23+
24+
try{
25+
constresult=awaitclient.query<TutorialData,TutorialDataVariables>({
26+
query:summaryQuery,
27+
variables:{
28+
tutorialId:context.tutorial.id,
29+
// version: context.tutorial.version.version, // TODO: reimplement version
30+
},
31+
})
32+
if(!result||!result.data||!result.data.tutorial){
33+
constmessage='No tutorial returned from tutorial config query'
34+
onError(newError(message))
35+
returnPromise.reject(message)
36+
}
37+
returnPromise.resolve(result.data.tutorial)
38+
}catch(error){
39+
constmessage:CR.ErrorMessage={title:'Failed to load tutorial config',description:error.message}
40+
onError(error)
41+
returnPromise.reject(message)
42+
}
43+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp