Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
N
Neos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
love_飞影
Neos
Commits
4545182b
Commit
4545182b
authored
Apr 06, 2024
by
Chunchi Che
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'fix/change_side' into 'main'
修复断线重连后,Side卡组消失的问题 See merge request
!361
parents
d672bb4c
68e8da12
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
6 deletions
+25
-6
src/stores/sideStore.ts
src/stores/sideStore.ts
+21
-2
src/ui/Side/index.tsx
src/ui/Side/index.tsx
+3
-3
src/ui/WaitRoom/index.tsx
src/ui/WaitRoom/index.tsx
+1
-1
No files found.
src/stores/sideStore.ts
View file @
4545182b
...
@@ -3,6 +3,8 @@ import { proxy } from "valtio";
...
@@ -3,6 +3,8 @@ import { proxy } from "valtio";
import
{
emptyDeck
,
IDeck
}
from
"
./deckStore
"
;
import
{
emptyDeck
,
IDeck
}
from
"
./deckStore
"
;
import
{
type
NeosStore
}
from
"
./shared
"
;
import
{
type
NeosStore
}
from
"
./shared
"
;
const
KEY
=
"
side_deck
"
;
export
enum
SideStage
{
export
enum
SideStage
{
NONE
=
0
,
// 没有进入SIDE阶段
NONE
=
0
,
// 没有进入SIDE阶段
SIDE_CHANGING
=
1
,
// 正在更换副卡组
SIDE_CHANGING
=
1
,
// 正在更换副卡组
...
@@ -15,10 +17,27 @@ export enum SideStage {
...
@@ -15,10 +17,27 @@ export enum SideStage {
class
SideStore
implements
NeosStore
{
class
SideStore
implements
NeosStore
{
stage
:
SideStage
=
SideStage
.
NONE
;
stage
:
SideStage
=
SideStage
.
NONE
;
deck
:
IDeck
=
emptyDeck
;
// 因为在上一局可能会出现断线重连,
// 所以side deck应该持久化存储在浏览器缓存里,
// 同时为了逻辑的收敛,暂时在`SideStore`提供接口。
//
// TODO: 后续应该有个`Storage`模块统一管理浏览器存储的数据,
// 这样一来卡组cdb还有文案的一些数据都可以做持久化存储,减少
// 网络请求量。
setSideDeck
(
deck
:
IDeck
)
{
try
{
localStorage
.
setItem
(
KEY
,
JSON
.
stringify
(
deck
));
}
catch
(
err
)
{
console
.
warn
(
`save side in localStorage error:
${
err
}
`
);
}
}
getSideDeck
():
IDeck
{
const
json
=
localStorage
.
getItem
(
KEY
);
return
json
?
JSON
.
parse
(
json
)
:
emptyDeck
;
}
reset
():
void
{
reset
():
void
{
this
.
stage
=
SideStage
.
NONE
;
this
.
stage
=
SideStage
.
NONE
;
this
.
deck
=
emptyDeck
;
}
}
}
}
...
...
src/ui/Side/index.tsx
View file @
4545182b
...
@@ -18,10 +18,9 @@ import { TpModal } from "./TpModal";
...
@@ -18,10 +18,9 @@ import { TpModal } from "./TpModal";
export
const
Component
:
React
.
FC
=
()
=>
{
export
const
Component
:
React
.
FC
=
()
=>
{
const
{
message
}
=
App
.
useApp
();
const
{
message
}
=
App
.
useApp
();
const
{
deck
:
sideDeck
}
=
sideStore
;
const
initialDeck
=
sideStore
.
getSideDeck
()
;
const
{
stage
}
=
useSnapshot
(
sideStore
);
const
{
stage
}
=
useSnapshot
(
sideStore
);
const
{
errorMsg
}
=
useSnapshot
(
roomStore
);
const
{
errorMsg
}
=
useSnapshot
(
roomStore
);
const
initialDeck
=
JSON
.
parse
(
JSON
.
stringify
(
sideDeck
));
const
[
deck
,
setDeck
]
=
useState
<
IDeck
>
(
initialDeck
);
const
[
deck
,
setDeck
]
=
useState
<
IDeck
>
(
initialDeck
);
const
[
selectedCard
,
setSelectedCard
]
=
useState
(
0
);
const
[
selectedCard
,
setSelectedCard
]
=
useState
(
0
);
const
navigate
=
useNavigate
();
const
navigate
=
useNavigate
();
...
@@ -55,11 +54,12 @@ export const Component: React.FC = () => {
...
@@ -55,11 +54,12 @@ export const Component: React.FC = () => {
});
});
};
};
const
onReset
=
()
=>
{
const
onReset
=
()
=>
{
setDeck
(
JSON
.
parse
(
JSON
.
stringify
(
sideDeck
))
);
setDeck
(
initialDeck
);
message
.
info
(
"
重置成功
"
);
message
.
info
(
"
重置成功
"
);
};
};
const
onSummit
=
()
=>
{
const
onSummit
=
()
=>
{
sendUpdateDeck
(
deck
);
sendUpdateDeck
(
deck
);
sideStore
.
setSideDeck
(
deck
);
};
};
useEffect
(()
=>
{
useEffect
(()
=>
{
...
...
src/ui/WaitRoom/index.tsx
View file @
4545182b
...
@@ -56,7 +56,7 @@ export const Component: React.FC = () => {
...
@@ -56,7 +56,7 @@ export const Component: React.FC = () => {
const
updateDeck
=
(
deck
:
IDeck
)
=>
{
const
updateDeck
=
(
deck
:
IDeck
)
=>
{
sendUpdateDeck
(
deck
);
sendUpdateDeck
(
deck
);
// 设置side里面的卡组
// 设置side里面的卡组
sideStore
.
deck
=
deck
;
sideStore
.
setSideDeck
(
deck
)
;
};
};
const
onDeckSelected
=
(
deckName
:
string
)
=>
{
const
onDeckSelected
=
(
deckName
:
string
)
=>
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment