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

Commit17a71b7

Browse files
committed
setup storage on server
1 parent619dd55 commit17a71b7

File tree

4 files changed

+71
-38
lines changed

4 files changed

+71
-38
lines changed

‎src/Channel.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import*asCRfrom'typings'
22
import*asvscodefrom'vscode'
3+
import*asstoragefrom'./services/storage'
34

45
importtutorialConfigfrom'./actions/tutorialConfig'
56
importsetupActionsfrom'./actions/setupActions'
@@ -21,19 +22,36 @@ class Channel implements Channel {
2122
constactionType:string=typeofaction==='string' ?action :action.type
2223
console.log('RECEIVED:',actionType)
2324
switch(actionType){
24-
case'TEST_RUN':
25-
vscode.commands.executeCommand('coderoad.run_test',action.payload)
25+
// continue from tutorial from local storage
26+
case'TUTORIAL_LOAD_STORED':
27+
consttutorial=storage.tutorial.get()
28+
conststepProgress=storage.stepProgress.get()
29+
this.send({type:'TUTORIAL_LOADED',payload:{tutorial, stepProgress}})
2630
return
31+
// clear tutorial local storage
32+
case'TUTORIAL_CLEAR':
33+
storage.tutorial.set(null)
34+
storage.stepProgress.set({})
35+
return
36+
// configure test runner, language, git
2737
case'TUTORIAL_CONFIG':
2838
tutorialConfig(action.payload)
39+
storage.tutorial.set(action.payload)
2940
return
41+
// run unit tests on step
42+
case'TEST_RUN':
43+
vscode.commands.executeCommand('coderoad.run_test',action.payload)
44+
return
45+
// load step actions (git commits, commands, open files)
3046
case'SETUP_ACTIONS':
3147
vscode.commands.executeCommand('coderoad.set_current_step',action.payload)
3248
setupActions(action.payload)
3349
return
50+
// load solution step actions (git commits, commands, open files)
3451
case'SOLUTION_ACTIONS':
3552
solutionActions(action.payload)
3653
return
54+
3755
default:
3856
console.log(`No match for action type:${actionType}`)
3957
return

‎src/editor/commands.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import*asvscodefrom'vscode'
2+
import*asstoragefrom'../services/storage'
23
importReactWebViewfrom'./ReactWebView'
34
importrunTestfrom'../actions/runTest'
45
import{isEmptyWorkspace}from'./workspace'
@@ -64,20 +65,28 @@ export const createCommands = ({vscodeExt}: CreateCommandProps) => {
6465
runTest({
6566
onSuccess:()=>{
6667
console.log('COMMAND TEST_PASS')
68+
// send test pass message back to client
6769
webview.send({type:'TEST_PASS', payload})
70+
// update local storage stepProgress
71+
storage.stepProgress.update({
72+
[payload.stepId]:true
73+
})
6874
vscode.window.showInformationMessage('PASS')
6975
},
7076
onFail:()=>{
7177
console.log('COMMAND TEST_FAIL')
78+
// send test fail message back to client
7279
webview.send({type:'TEST_FAIL', payload})
7380
vscode.window.showWarningMessage('FAIL')
7481
},
7582
onError:()=>{
7683
console.log('COMMAND TEST_ERROR')
84+
// send test error message back to client
7785
webview.send({type:'TEST_ERROR', payload})
7886
},
7987
onRun:()=>{
8088
console.log('COMMAND TEST_RUN')
89+
// send test run message back to client
8190
webview.send({type:'TEST_RUN', payload})
8291
}
8392
})

‎src/services/storage/index.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import*asGfrom'typings/graphql'
2+
3+
// localStorage not available on client
4+
// must be stored in editor
5+
6+
classStorage<T>{
7+
privatekey:string
8+
// TODO: replace somehow with localStorage
9+
// window.localStorage not working inside of vscode
10+
privatestorage=localStorage
11+
constructor({key, value}:{key:string,value:T}){
12+
this.key=key
13+
this.set(value)
14+
}
15+
publicget=async():Promise<T|null>=>{
16+
constvalue=awaitthis.storage.getItem(this.key)
17+
if(value){
18+
returnJSON.parse(value)
19+
}
20+
returnnull
21+
}
22+
publicset=(value:T):void=>{
23+
conststringValue=JSON.stringify(value)
24+
this.storage.setItem(this.key,stringValue)
25+
}
26+
publicupdate=async(value:T):Promise<void>=>{
27+
constcurrent=awaitthis.get()
28+
this.set({
29+
...current,
30+
...value,
31+
})
32+
}
33+
}
34+
35+
exportconsttutorial=newStorage<G.Tutorial|null>({
36+
key:'coderoad:tutorial',
37+
value:null
38+
})
39+
exportconststepProgress=newStorage<{[stepId:string]:boolean}>({
40+
key:'coderoad:progress',
41+
value:{}
42+
})

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

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp