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

Commit5e88996

Browse files
committed
setup local storage of tutorial,progress,position
1 parent92522b1 commit5e88996

File tree

4 files changed

+59
-106
lines changed

4 files changed

+59
-106
lines changed

‎src/editor/storage.ts

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

‎src/services/storage.ts

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

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

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import{assign}from'xstate'
22
import*asGfrom'typings/graphql'
33
import*asCRfrom'typings'
4+
import*asstoragefrom'./storage'
45

56
exportdefault{
67
setTutorial:assign({
78
tutorial:(context:CR.MachineContext,event:CR.MachineEvent):any=>{
8-
returnevent.payload.tutorial
9+
const{tutorial}=event.payload
10+
storage.tutorial.set(tutorial)
11+
returntutorial
912
},
1013
}),
1114
//@ts-ignore
@@ -23,6 +26,8 @@ export default {
2326
stepId:version.levels[0].stages[0].steps[0].id,
2427
}
2528

29+
storage.position.set(position)
30+
2631
returnposition
2732
},
2833
}),
@@ -42,10 +47,14 @@ export default {
4247

4348
console.log('step load next',step.id,position.stepId)
4449

45-
return{
50+
constnextPosition:CR.Position={
4651
...position,
4752
stepId:step.id
4853
}
54+
55+
storage.position.set(nextPosition)
56+
57+
returnnextPosition
4958
},
5059
}),
5160
//@ts-ignore
@@ -63,11 +72,15 @@ export default {
6372

6473
console.log('stage load next',stage.id,position.stageId)
6574

66-
return{
75+
constnextPosition:CR.Position={
6776
...position,
6877
stageId:stage.id,
6978
stepId:stage.steps[0].id,
7079
}
80+
81+
storage.position.set(nextPosition)
82+
83+
returnnextPosition
7184
},
7285
}),
7386
//@ts-ignore
@@ -83,11 +96,15 @@ export default {
8396

8497
console.log('level load next',level.id,position.levelId)
8598

86-
return{
99+
constnextPosition:CR.Position={
87100
levelId:level.id,
88101
stageId:level.stages[0].id,
89102
stepId:level.stages[0].steps[0].id,
90103
}
104+
105+
storage.position.set(nextPosition)
106+
107+
returnnextPosition
91108
},
92109
}),
93110
//@ts-ignore
@@ -100,6 +117,8 @@ export default {
100117

101118
currentProgress.steps[stepId]=true
102119

120+
storage.progress.set(currentProgress)
121+
103122
returncurrentProgress
104123
},
105124
}),
@@ -114,28 +133,35 @@ export default {
114133

115134
progress.stages[stageId]=true
116135

136+
storage.progress.set(progress)
137+
117138
returnprogress
118139
},
119140
}),
120141
//@ts-ignore
121142
reset:assign({
122143
tutorial(){
144+
storage.tutorial.set(null)
123145
returnnull
124146
},
125147
progress():CR.Progress{
126-
return{
148+
constprogress:CR.Progress={
127149
levels:{},
128150
stages:{},
129151
steps:{},
130152
complete:false
131153
}
154+
storage.progress.set(progress)
155+
returnprogress
132156
},
133157
position():CR.Position{
134-
return{
158+
constposition:CR.Position={
135159
levelId:'',
136160
stageId:'',
137161
stepId:''
138162
}
163+
storage.position.set(position)
164+
returnposition
139165
}
140166
})
141167
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import*asCRfrom'typings'
2+
import*asGfrom'typings/graphql'
3+
4+
// localStorage
5+
6+
classStorage<T>{
7+
privatekey:string
8+
privatestorage=localStorage
9+
constructor(key:string){
10+
this.key=key
11+
}
12+
publicget=(key:string):T|null=>{
13+
constvalue=this.storage.getItem(this.key)
14+
if(value){
15+
returnJSON.parse(value)
16+
}
17+
returnnull
18+
}
19+
publicset=(value:T):void=>{
20+
conststringValue=JSON.stringify(value)
21+
this.storage.setItem(this.key,stringValue)
22+
}
23+
}
24+
25+
exportconsttutorial=newStorage<G.Tutorial|null>('coderoad:tutorial')
26+
exportconstposition=newStorage<CR.Position>('coderoad:position')
27+
exportconstprogress=newStorage<CR.Progress>('coderoad:progress')

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp