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

Commit50cad58

Browse files
committed
setup initial start/loaded actions
1 parent0133ab8 commit50cad58

File tree

8 files changed

+98
-29
lines changed

8 files changed

+98
-29
lines changed

‎src/editor/ReactWebView.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import*aspathfrom'path'
22
import*asCRfrom'typings'
33
import*asvscodefrom'vscode'
4+
import{tutorialModel}from'../extension'
45

56
constgetNonce=():string=>{
67
lettext=''
@@ -44,6 +45,10 @@ class ReactWebView {
4445
case'TUTORIAL_START':
4546
console.log('TUTORIAL_START called')
4647
console.log(action)
48+
if(typeofaction==='string'||!action.payload||!action.payload.id){
49+
thrownewError('No tutorial id on tutorial start action')
50+
}
51+
tutorialModel.launch(action.payload.id)
4752
break
4853
// add other cases
4954
default:

‎src/services/tutorial/index.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import*asGfrom'typings/graphql'
22
import*asCRfrom'typings'
33
import*asgitfrom'../../services/git'
4+
import{machine}from'../../extension'
45
import*asstoragefrom'../storage'
56
importapifrom'../api'
67
importtutorialQueryfrom'../../services/api/gql/getTutorial'
@@ -60,13 +61,16 @@ class Tutorial implements TutorialModel {
6061
// })
6162

6263
}
63-
publicasynclaunch(tutorialId:string){
64+
publiclaunch=async(tutorialId:string)=>{
6465
console.log('launch tutorial')
66+
machine.send('TUTORIAL_START')
6567

6668
const{tutorial}:{tutorial:G.Tutorial|null}=awaitapi.request(tutorialQuery,{
6769
tutorialId,// TODO: add selection of tutorial id
6870
})
6971

72+
console.log('tutorial',tutorial)
73+
7074
if(!tutorial){
7175
thrownewError(`Tutorial${tutorialId} not found`)
7276
}
@@ -83,6 +87,8 @@ class Tutorial implements TutorialModel {
8387
}
8488
// version containing level data
8589
this.version=tutorial.version
90+
console.log('version',this.version)
91+
8692
// set initial position
8793
this.position={
8894
levelId:this.version.levels[0].id,
@@ -112,7 +118,9 @@ class Tutorial implements TutorialModel {
112118
storage.setPosition(this.position),
113119
storage.setProgress(this.progress)
114120
])
115-
// machine.send('TUTORIAL_LOADED')
121+
122+
console.log('tutorial loaded')
123+
machine.send('TUTORIAL_LOADED')
116124
}
117125

118126
publicasynchasExisting():Promise<boolean>{

‎web-app/src/App.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as CR from 'typings'
44

55
importclientfrom'./services/apollo'
66
import{SET_STATUS}from'./services/apollo/mutations'
7+
importcurrentTutorialfrom'./services/current'
78
importDebuggerfrom'./components/Debugger'
89
importRoutesfrom'./Routes'
910
import{send}from'./utils/vscode'
@@ -39,11 +40,15 @@ const App = () => {
3940

4041
}elseif(message.type==='SET_DATA'){
4142
// SET_DATA - set state machine context
42-
const{ progress, position}=message.payload.data
43+
console.log('DATA')
44+
const{ progress, position}=message.payload
4345
if(process.env.REACT_APP_DEBUG){
4446
console.log(`Position:${position.levelId}/${position.stageId}/${position.stepId}`)
4547
setDebuggerInfo({ progress, position})
4648
}
49+
console.log('set currentTutorial')
50+
currentTutorial.set({ position})
51+
console.log('setStatus')
4752
setStatus({variables:{ progress, position}})
4853
}
4954
}
Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import*asReactfrom'react'
22

3+
importcurrentTutorialfrom'../../../services/current'
34
import*asCRfrom'typings'
45
import*asTfrom'typings/graphql'
56
importTutorialItemfrom'./TutorialItem'
@@ -10,25 +11,31 @@ interface Props {
1011
}
1112

1213
constTutorialList=(props:Props)=>{
13-
constonSelect=(tutorial:T.Tutorial)=>props.onNew({
14-
type:'TUTORIAL_START',
15-
payload:{
16-
id:tutorial.id,
17-
version:tutorial.version,
18-
}
19-
})
14+
constonSelect=(tutorial:T.Tutorial)=>{
15+
currentTutorial.set({
16+
tutorialId:tutorial.id,
17+
version:tutorial.version.version,
18+
})
19+
props.onNew({
20+
type:'TUTORIAL_START',
21+
payload:{
22+
id:tutorial.id,
23+
version:tutorial.version.version,
24+
}
25+
})
26+
}
2027
return(
21-
<div>
22-
{props.tutorialList.map((tutorial:T.Tutorial)=>(
23-
<TutorialItem
24-
key={tutorial.id}
25-
onSelect={()=>onSelect(tutorial)}
26-
title={tutorial.title||''}
27-
text={tutorial.text||''}
28-
/>
29-
))}
30-
</div>
31-
)
32-
}
28+
<div>
29+
{props.tutorialList.map((tutorial:T.Tutorial)=>(
30+
<TutorialItem
31+
key={tutorial.id}
32+
onSelect={()=>onSelect(tutorial)}
33+
title={tutorial.title||''}
34+
text={tutorial.text||''}
35+
/>
36+
))}
37+
</div>
38+
)
39+
}
3340

3441
exportdefaultTutorialList

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as React from 'react'
22
import{useQuery}from'@apollo/react-hooks'
33
import*asTfrom'typings/graphql'
44

5+
importcurrentTutorialfrom'../../../services/current'
56
importErrorViewfrom'../../../components/Error'
67
importLevelfrom'./Level'
78
importqueryLevelfrom'./queryLevel'
@@ -26,11 +27,12 @@ interface ContainerProps {
2627
}
2728

2829
constLevelSummaryPageContainer=(props:ContainerProps)=>{
30+
const{ tutorialId, version,position:{ levelId}}=currentTutorial.get()
2931
const{ loading, error, data}=useQuery(queryLevel,{
3032
variables:{
31-
tutorialId:'1',
32-
version:'0.1.0',
33-
levelId:'1',
33+
tutorialId,
34+
version,
35+
levelId,
3436
},
3537
})
3638

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import*asReactfrom'react'
22
import{useQuery}from'@apollo/react-hooks'
33

4+
importcurrentTutorialfrom'../../../services/current'
45
importErrorViewfrom'../../../components/Error'
56
importStagefrom'./Stage'
67
importqueryStagefrom'./queryStage'
@@ -10,11 +11,12 @@ interface PageProps {
1011
}
1112

1213
constStageSummaryPageContainer=(props:PageProps)=>{
14+
const{ tutorialId, version,position:{ stageId}}=currentTutorial.get()
1315
const{ loading, error, data}=useQuery(queryStage,{
1416
variables:{
15-
tutorialId:'1',
16-
version:'0.1.0',
17-
stageId:'1',
17+
tutorialId,
18+
version,
19+
stageId,
1820
},
1921
})
2022
if(loading){

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@ import { useQuery } from '@apollo/react-hooks'
33

44
importquerySummaryfrom'./querySummary'
55
importSummaryfrom'./Summary'
6+
importcurrentTutorialfrom'../../../services/current'
67
importErrorViewfrom'../../../components/Error'
78

89
interfacePageProps{
910
send(action:string):void
1011
}
1112

1213
constSummaryPage=(props:PageProps)=>{
14+
const{ tutorialId}=currentTutorial.get()
1315
const{ loading, error, data}=useQuery(querySummary,{
1416
variables:{
15-
tutorialId:'1',
17+
tutorialId,
1618
},
1719
})
1820

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import*asCRfrom'typings'
2+
3+
interfaceCurrentTutorialParams{
4+
tutorialId:string
5+
version:string
6+
position:CR.Position
7+
}
8+
9+
interfaceSetCurrentTutorialParams{
10+
tutorialId?:string
11+
version?:string
12+
position?:CR.Position
13+
}
14+
15+
classCurrentTutorial{
16+
privatetutorialId=''
17+
privateversion=''
18+
privateposition:CR.Position={levelId:'',stageId:'',stepId:''}
19+
publicset({tutorialId, version, position}:SetCurrentTutorialParams){
20+
this.tutorialId=tutorialId||this.tutorialId
21+
this.version=version||this.version
22+
this.position=position||this.position
23+
}
24+
publicget():CurrentTutorialParams{
25+
return{
26+
tutorialId:this.tutorialId,
27+
version:this.version,
28+
position:this.position,
29+
}
30+
}
31+
publicclear(){
32+
this.tutorialId=''
33+
this.version=''
34+
this.position={levelId:'',stageId:'',stepId:''}
35+
}
36+
}
37+
38+
exportdefaultnewCurrentTutorial()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp