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

Commit0f992bf

Browse files
committed
setup storage in editor channel
1 parente49165c commit0f992bf

File tree

3 files changed

+107
-46
lines changed

3 files changed

+107
-46
lines changed

‎src/Channel.ts

Lines changed: 94 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import*asCRfrom'typings'
2+
import*asGfrom'typings/graphql'
23
import*asvscodefrom'vscode'
34

45
importStoragefrom'./services/storage'
56
importtutorialConfigfrom'./actions/tutorialConfig'
67
importsetupActionsfrom'./actions/setupActions'
78
importsolutionActionsfrom'./actions/solutionActions'
89

10+
911
interfaceChannel{
1012
receive(action:CR.Action):Promise<void>
1113
send(action:CR.Action):Promise<void>
@@ -18,17 +20,25 @@ interface ChannelProps {
1820

1921
classChannelimplementsChannel{
2022
privatepostMessage:(action:CR.Action)=>Thenable<boolean>
21-
privatecurrentTutorial:Storage<{id:string|null,version:string|null}>
22-
privatestepProgress:Storage<CR.StepProgress>|undefined
23+
privatecurrentTutorial:Storage<G.Tutorial|null>
24+
privatestepProgress:Storage<CR.StepProgress>
2325
privateworkspaceState:vscode.Memento
2426
constructor({postMessage, workspaceState}:ChannelProps){
2527
this.postMessage=postMessage
2628
this.workspaceState=workspaceState
2729

28-
this.currentTutorial=newStorage<{id:string|null,version:string|null}>({
30+
// local storage of current tutorial for continuing tutorials
31+
this.currentTutorial=newStorage<G.Tutorial|null>({
2932
key:'coderoad:currentTutorial',
3033
storage:workspaceState,
31-
defaultValue:{id:null,version:null}
34+
defaultValue:null,
35+
})
36+
37+
// initialized for consistent typings. unused
38+
this.stepProgress=newStorage<CR.StepProgress>({
39+
key:'coderoad:stepProgress',
40+
storage:this.workspaceState,
41+
defaultValue:{}
3242
})
3343
}
3444

@@ -38,39 +48,94 @@ class Channel implements Channel {
3848
console.log('RECEIVED:',actionType)
3949
switch(actionType){
4050
// continue from tutorial from local storage
41-
case'TUTORIAL_LOAD_STORED':
42-
consttutorial=awaitthis.currentTutorial.get()
51+
case'EDITOR_TUTORIAL_LOAD':
52+
consttutorial:G.Tutorial|null=awaitthis.currentTutorial.get()
4353

44-
if(tutorial&&tutorial.id&&tutorial.version){
45-
this.stepProgress=newStorage<CR.StepProgress>({
46-
key:`coderoad:stepProgress:${tutorial.id}:${tutorial.version}`,
47-
storage:this.workspaceState,
48-
defaultValue:{}
49-
})
50-
conststepProgress=awaitthis.stepProgress.get()
51-
console.log('looking at stored')
52-
console.log(JSON.stringify(tutorial))
53-
console.log(JSON.stringify(stepProgress))
54-
// communicate to client the tutorial & stepProgress state
55-
this.send({type:'CONTINUE_TUTORIAL',payload:{tutorial, stepProgress}})
56-
}else{
54+
// new tutorial
55+
if(!tutorial||!tutorial.id||!tutorial.version){
5756
this.send({type:'NEW_TUTORIAL'})
57+
return
58+
}
59+
60+
// continue tutorial
61+
// setup progress for specific tutorial
62+
this.stepProgress=newStorage<CR.StepProgress>({
63+
key:`coderoad:stepProgress:${tutorial.id}:${tutorial.version}`,
64+
storage:this.workspaceState,
65+
defaultValue:{}
66+
})
67+
conststepProgress=awaitthis.stepProgress.get()
68+
console.log('looking at stored')
69+
console.log(JSON.stringify(tutorial))
70+
console.log(JSON.stringify(stepProgress))
71+
constprogress:CR.Progress={
72+
steps:stepProgress,
73+
stages:{},
74+
levels:{},
75+
complete:false
76+
}
77+
78+
constposition:CR.Position={
79+
stepId:'',
80+
stageId:'',
81+
levelId:'',
5882
}
5983

84+
// calculate progress from tutorial & stepProgress
85+
for(constleveloftutorial.version.levels){
86+
for(conststageoflevel.stages){
87+
// set stage progress
88+
conststageComplete:boolean=stage.steps.every((step:G.Step)=>{
89+
returnstepProgress[step.id]
90+
})
91+
if(stageComplete){
92+
progress.stages[stage.id]=true
93+
}elseif(!position.stageId.length){
94+
// set stage amd step position
95+
position.stageId=stage.id
96+
//@ts-ignore
97+
position.stepId=stage.steps.find((step:G.Step)=>!stepProgress[step.id]).id
98+
}
99+
}
100+
// set level progress
101+
constlevelComplete:boolean=level.stages.every((stage:G.Stage)=>{
102+
returnprogress.stages[stage.id]
103+
})
104+
if(levelComplete){
105+
progress.levels[level.id]=true
106+
}elseif(!position.levelId.length){
107+
position.levelId=level.id
108+
}
109+
}
110+
// set tutorial progress
111+
progress.complete=tutorial.version.levels.every((level:G.Level)=>{
112+
returnprogress.levels[level.id]
113+
})
114+
// communicate to client the tutorial & stepProgress state
115+
this.send({type:'CONTINUE_TUTORIAL',payload:{tutorial, progress, position}})
116+
60117
return
61118
// clear tutorial local storage
62119
case'TUTORIAL_CLEAR':
63-
this.currentTutorial.set({id:null,version:null})
120+
this.currentTutorial.set(null)
64121

65122
// reset tutorial progress on clear
66-
if(this.stepProgress){
67-
this.stepProgress.set({})
68-
}
123+
this.stepProgress.set({})
69124
return
70125
// configure test runner, language, git
71-
case'TUTORIAL_CONFIG':
72-
tutorialConfig(action.payload)
73-
this.currentTutorial.set(action.payload)
126+
case'EDITOR_TUTORIAL_CONFIG':
127+
consttutorialInfo=action.payload.tutorial
128+
console.log('tutorialConfig',JSON.stringify(tutorialInfo))
129+
if(!this.stepProgress){
130+
// setup progress for new tutorials
131+
this.stepProgress=newStorage<CR.StepProgress>({
132+
key:`coderoad:stepProgress:${tutorialInfo.id}:${tutorialInfo.version.version}`,
133+
storage:this.workspaceState,
134+
defaultValue:{}
135+
})
136+
}
137+
tutorialConfig(tutorialInfo)
138+
this.currentTutorial.set(tutorialInfo)
74139
return
75140
// run unit tests on step
76141
case'TEST_RUN':
@@ -97,10 +162,9 @@ class Channel implements Channel {
97162
switch(action.type){
98163
case'TEST_PASS':
99164
// update local storage stepProgress
100-
// stepProgress.update({
101-
// [action.payload.stepId]: true
102-
// })
103-
return
165+
this.stepProgress.update({
166+
[action.payload.stepId]:true
167+
})
104168
}
105169

106170
constsuccess=awaitthis.postMessage(action)

‎src/editor/commands.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import*asvscodefrom'vscode'
2-
import{EditorStorage}from'typings'
32
importReactWebViewfrom'./ReactWebView'
43
importrunTestfrom'../actions/runTest'
54
import{isEmptyWorkspace}from'./workspace'

‎src/services/storage/index.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,36 @@ import * as vscode from 'vscode'
99
classStorage<T>{
1010
privatekey:string
1111
privatestorage:vscode.Memento
12-
constructor({key, storage, defaultValue}:{key:string,storage:vscode.Memento,defaultValue?:T}){
12+
privatedefaultValue:T
13+
constructor({key, storage, defaultValue}:{key:string,storage:vscode.Memento,defaultValue:T}){
1314
this.storage=storage
1415
this.key=key
15-
// set default if none exists
16-
if(!defaultValue){
17-
return
18-
}
19-
this.get().then((value:T|null)=>{
20-
if(!value){
21-
this.set(defaultValue)
22-
}
23-
})
16+
this.defaultValue=defaultValue
2417
}
25-
publicget=async():Promise<T|null>=>{
18+
publicget=async():Promise<T>=>{
2619
constvalue:string|undefined=awaitthis.storage.get(this.key)
27-
//console.log(`STORAGE.get ${this.key} : ${JSON.stringify(value)}`)
20+
console.log(`STORAGE.get${this.key} :${value}`)
2821
if(value){
2922
returnJSON.parse(value)
3023
}
31-
returnnull
24+
returnthis.defaultValue
3225
}
3326
publicset=(value:T):void=>{
3427
conststringValue=JSON.stringify(value)
35-
//console.log(`STORAGE.set ${this.key} ${JSON.stringify(value)}`)
28+
console.log(`STORAGE.set${this.key}${JSON.stringify(value)}`)
3629
this.storage.update(this.key,stringValue)
3730
}
3831
publicupdate=async(value:T):Promise<void>=>{
3932
constcurrent=awaitthis.get()
40-
this.set({
33+
constnext=JSON.stringify({
4134
...current,
4235
...value,
4336
})
37+
console.log(`STORAGE.update${this.key}${next}`)
38+
this.storage.update(this.key,next)
39+
}
40+
publicreset=()=>{
41+
this.set(this.defaultValue)
4442
}
4543
}
4644

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp