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
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
2
Merge Requests
2
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
MyCard
Neos
Commits
f6d69df9
Commit
f6d69df9
authored
Aug 31, 2023
by
Chunchi Che
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
optimize OptionModal.tsx
parent
7553a952
Pipeline
#23302
passed with stages
in 15 minutes and 17 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
10 deletions
+51
-10
src/service/duel/selectOption.ts
src/service/duel/selectOption.ts
+1
-1
src/ui/Duel/Message/OptionModal.tsx
src/ui/Duel/Message/OptionModal.tsx
+50
-9
No files found.
src/service/duel/selectOption.ts
View file @
f6d69df9
...
...
@@ -14,7 +14,7 @@ export default async (selectOption: ygopro.StocGameMessage.MsgSelectOption) => {
await
Promise
.
all
(
options
.
map
(
async
({
code
,
response
})
=>
{
const
meta
=
fetchCard
(
code
>>
4
);
const
msg
=
getCardStr
(
meta
,
code
&
0xf
)
||
"
[?]
"
;
const
msg
=
getCardStr
(
meta
,
code
&
0xf
)
??
"
[?]
"
;
return
{
msg
,
response
};
}),
),
...
...
src/ui/Duel/Message/OptionModal.tsx
View file @
f6d69df9
import
{
CheckCard
}
from
"
@ant-design/pro-components
"
;
import
{
Button
}
from
"
antd
"
;
import
{
Button
,
Segmented
}
from
"
antd
"
;
import
React
,
{
useState
}
from
"
react
"
;
import
{
proxy
,
useSnapshot
}
from
"
valtio
"
;
...
...
@@ -23,14 +23,18 @@ const defaultStore = {
};
const
store
=
proxy
(
defaultStore
);
// 一页最多4个选项
const
MAX_NUM_PER_PAGE
=
4
;
export
const
OptionModal
=
()
=>
{
const
snap
=
useSnapshot
(
store
);
const
{
title
,
isOpen
,
options
}
=
snap
;
const
[
selected
,
setSelected
]
=
useState
<
number
|
undefined
>
(
undefined
);
// options可能太多,因此分页展示
const
[
page
,
setPage
]
=
useState
(
0
);
const
maxPage
=
Math
.
ceil
(
options
.
length
/
MAX_NUM_PER_PAGE
);
const
on
Click
=
()
=>
{
const
on
Summit
=
()
=>
{
if
(
selected
!==
undefined
)
{
sendSelectOptionResponse
(
selected
);
rs
();
...
...
@@ -42,20 +46,57 @@ export const OptionModal = () => {
title=
{
title
}
open=
{
isOpen
}
footer=
{
<
Button
disabled=
{
selected
===
undefined
}
onClick=
{
on
Click
}
>
<
Button
disabled=
{
selected
===
undefined
}
onClick=
{
on
Summit
}
>
确定
</
Button
>
}
>
<
CheckCard
.
Group
bordered
size=
"small"
onChange=
{
setSelected
as
any
}
>
{
options
.
map
((
option
,
idx
)
=>
(
<
CheckCard
key=
{
idx
}
title=
{
option
.
msg
}
value=
{
option
.
response
}
/>
))
}
<
Selector
page=
{
page
}
maxPage=
{
maxPage
}
onChange=
{
setPage
as
any
}
/>
<
CheckCard
.
Group
bordered
style=
{
{
display
:
"
grid
"
,
gridTemplateColumns
:
"
repeat(2, 1fr)
"
,
gap
:
"
10px
"
,
}
}
onChange=
{
setSelected
as
any
}
>
{
options
.
slice
(
page
*
MAX_NUM_PER_PAGE
,
Math
.
min
((
page
+
1
)
*
MAX_NUM_PER_PAGE
,
options
.
length
),
)
.
map
((
option
,
idx
)
=>
(
<
CheckCard
key=
{
idx
}
style=
{
{
width
:
"
200px
"
,
marginInlineEnd
:
0
,
marginBlockEnd
:
0
}
}
title=
{
option
.
msg
}
value=
{
option
.
response
}
/>
))
}
</
CheckCard
.
Group
>
</
NeosModal
>
);
};
/* 选择区域 */
const
Selector
:
React
.
FC
<
{
page
:
number
;
maxPage
:
number
;
onChange
:
(
value
:
number
)
=>
void
;
}
>
=
({
page
,
maxPage
,
onChange
})
=>
maxPage
>
1
?
(
<
Segmented
block
options=
{
Array
.
from
({
length
:
maxPage
}).
map
((
_
,
idx
)
=>
idx
)
}
style=
{
{
margin
:
"
10px 0
"
}
}
value=
{
page
}
onChange=
{
onChange
as
any
}
></
Segmented
>
)
:
(
<></>
);
let
rs
:
(
v
?:
any
)
=>
void
=
()
=>
{};
export
const
displayOptionModal
=
async
(
title
:
string
,
options
:
Options
)
=>
{
store
.
title
=
title
;
...
...
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