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
170077ea
Commit
170077ea
authored
Aug 31, 2023
by
Chunchi Che
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
parent
e09a99cf
Pipeline
#23304
passed with stages
in 12 minutes and 47 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
19 deletions
+35
-19
src/ui/Duel/Message/OptionModal.tsx
src/ui/Duel/Message/OptionModal.tsx
+6
-4
src/ui/Duel/Message/SelectCardsModal/index.tsx
src/ui/Duel/Message/SelectCardsModal/index.tsx
+29
-15
No files found.
src/ui/Duel/Message/OptionModal.tsx
View file @
170077ea
import
{
CheckCard
}
from
"
@ant-design/pro-components
"
;
import
{
CheckCard
}
from
"
@ant-design/pro-components
"
;
import
{
Button
,
Segmented
}
from
"
antd
"
;
import
{
Button
,
Segmented
}
from
"
antd
"
;
import
{
chunk
}
from
"
lodash-es
"
;
import
{
chunk
}
from
"
lodash-es
"
;
import
React
,
{
useState
}
from
"
react
"
;
import
React
,
{
use
Effect
,
use
State
}
from
"
react
"
;
import
{
proxy
,
useSnapshot
}
from
"
valtio
"
;
import
{
proxy
,
useSnapshot
}
from
"
valtio
"
;
import
{
import
{
...
@@ -34,9 +34,7 @@ export const OptionModal = () => {
...
@@ -34,9 +34,7 @@ export const OptionModal = () => {
// options可能太多,因此分页展示
// options可能太多,因此分页展示
const
[
page
,
setPage
]
=
useState
(
0
);
const
[
page
,
setPage
]
=
useState
(
0
);
const
maxPage
=
Math
.
ceil
(
options
.
length
/
MAX_NUM_PER_PAGE
);
const
maxPage
=
Math
.
ceil
(
options
.
length
/
MAX_NUM_PER_PAGE
);
const
[
selecteds
,
setSelecteds
]
=
useState
<
number
[][]
>
(
const
[
selecteds
,
setSelecteds
]
=
useState
<
number
[][]
>
([]);
Array
.
from
({
length
:
maxPage
}).
map
((
_
)
=>
[]),
);
const
grouped
=
chunk
(
options
,
MAX_NUM_PER_PAGE
);
const
grouped
=
chunk
(
options
,
MAX_NUM_PER_PAGE
);
const
onSummit
=
()
=>
{
const
onSummit
=
()
=>
{
...
@@ -48,6 +46,10 @@ export const OptionModal = () => {
...
@@ -48,6 +46,10 @@ export const OptionModal = () => {
}
}
};
};
useEffect
(()
=>
{
setSelecteds
(
Array
.
from
({
length
:
maxPage
}).
map
((
_
)
=>
[]));
},
[
options
]);
return
(
return
(
<
NeosModal
<
NeosModal
title=
{
title
}
title=
{
title
}
...
...
src/ui/Duel/Message/SelectCardsModal/index.tsx
View file @
170077ea
...
@@ -46,8 +46,8 @@ export const SelectCardsModal: React.FC<SelectCardsModalProps> = ({
...
@@ -46,8 +46,8 @@ export const SelectCardsModal: React.FC<SelectCardsModalProps> = ({
onCancel
,
onCancel
,
onFinish
,
onFinish
,
})
=>
{
})
=>
{
// FIXME: handle `selecteds`
const
grouped
=
groupBy
(
selectables
,
(
option
)
=>
option
.
location
?.
zone
!
);
const
[
result
,
setResult
]
=
useState
<
Option
[]
>
([]);
const
[
result
,
setResult
]
=
useState
<
[
ygopro
.
CardZone
,
Option
[]]
[]
>
([]);
const
[
submitable
,
setSubmitable
]
=
useState
(
false
);
const
[
submitable
,
setSubmitable
]
=
useState
(
false
);
const
hint
=
useSnapshot
(
matStore
.
hint
);
const
hint
=
useSnapshot
(
matStore
.
hint
);
...
@@ -56,14 +56,21 @@ export const SelectCardsModal: React.FC<SelectCardsModalProps> = ({
...
@@ -56,14 +56,21 @@ export const SelectCardsModal: React.FC<SelectCardsModalProps> = ({
const
minMaxText
=
min
===
max
?
min
:
`
${
min
}
-
${
max
}
`
;
const
minMaxText
=
min
===
max
?
min
:
`
${
min
}
-
${
max
}
`
;
// const isMultiple = !single && max > 1;
useEffect
(()
=>
{
// FIXME: 如果想上面这样鞋会panic,还不是很清楚原因,先放着后面再优化
const
initial
:
[
ygopro
.
CardZone
,
Option
[]][]
=
grouped
.
map
(([
zone
,
_
])
=>
[
const
isMultiple
=
true
;
zone
,
[]
as
Option
[],
]);
if
(
initial
.
length
>
0
)
{
setResult
(
initial
);
}
},
[
selectables
]);
// 判断是否可以提交
// 判断是否可以提交
useEffect
(()
=>
{
useEffect
(()
=>
{
const
flatResult
=
result
.
map
(([
_
,
v
])
=>
v
).
flat
();
const
[
sumLevel1
,
sumLevel2
]
=
([
"
level1
"
,
"
level2
"
]
as
const
).
map
((
key
)
=>
const
[
sumLevel1
,
sumLevel2
]
=
([
"
level1
"
,
"
level2
"
]
as
const
).
map
((
key
)
=>
[...
mustSelects
,
...
r
esult
]
[...
mustSelects
,
...
flatR
esult
]
.
map
((
option
)
=>
option
[
key
]
||
0
)
.
map
((
option
)
=>
option
[
key
]
||
0
)
.
reduce
((
sum
,
current
)
=>
sum
+
current
,
0
),
.
reduce
((
sum
,
current
)
=>
sum
+
current
,
0
),
);
);
...
@@ -72,12 +79,10 @@ export const SelectCardsModal: React.FC<SelectCardsModalProps> = ({
...
@@ -72,12 +79,10 @@ export const SelectCardsModal: React.FC<SelectCardsModalProps> = ({
:
sumLevel1
===
totalLevels
||
sumLevel2
===
totalLevels
;
:
sumLevel1
===
totalLevels
||
sumLevel2
===
totalLevels
;
setSubmitable
(
setSubmitable
(
single
single
?
r
esult
.
length
===
1
?
flatR
esult
.
length
===
1
:
result
.
length
>=
min
&&
r
esult
.
length
<=
max
&&
levelMatched
,
:
flatResult
.
length
>=
min
&&
flatR
esult
.
length
<=
max
&&
levelMatched
,
);
);
},
[
result
.
length
]);
},
[
result
]);
const
grouped
=
groupBy
(
selectables
,
(
option
)
=>
option
.
location
?.
zone
!
);
const
zoneOptions
=
grouped
.
map
((
x
)
=>
({
const
zoneOptions
=
grouped
.
map
((
x
)
=>
({
value
:
x
[
0
],
value
:
x
[
0
],
...
@@ -126,7 +131,9 @@ export const SelectCardsModal: React.FC<SelectCardsModalProps> = ({
...
@@ -126,7 +131,9 @@ export const SelectCardsModal: React.FC<SelectCardsModalProps> = ({
<
Button
<
Button
type=
"primary"
type=
"primary"
disabled=
{
!
submitable
}
disabled=
{
!
submitable
}
onClick=
{
()
=>
onSubmit
([...
mustSelects
,
...
result
])
}
onClick=
{
()
=>
onSubmit
([...
mustSelects
,
...
result
.
map
(([
_
,
v
])
=>
v
).
flat
()])
}
>
>
{
submitText
}
{
submitText
}
</
Button
>
</
Button
>
...
@@ -144,11 +151,18 @@ export const SelectCardsModal: React.FC<SelectCardsModalProps> = ({
...
@@ -144,11 +151,18 @@ export const SelectCardsModal: React.FC<SelectCardsModalProps> = ({
options
[
0
]
===
selectedZone
&&
(
options
[
0
]
===
selectedZone
&&
(
<
div
className=
{
styles
[
"
container
"
]
}
key=
{
i
}
>
<
div
className=
{
styles
[
"
container
"
]
}
key=
{
i
}
>
<
CheckCard
.
Group
<
CheckCard
.
Group
onChange=
{
(
res
)
=>
{
onChange=
{
(
res
:
any
)
=>
{
setResult
((
isMultiple
?
res
:
[
res
])
as
any
);
const
newRes
:
[
ygopro
.
CardZone
,
Option
[]][]
=
result
.
map
(
([
k
,
v
])
=>
[
k
,
k
===
selectedZone
?
res
:
v
],
);
setResult
(
newRes
);
}
}
}
}
value=
{
result
.
find
(([
k
,
_
])
=>
k
===
selectedZone
)?.[
1
]
??
([]
as
any
)
}
// TODO 考虑如何设置默认值,比如只有一个的,就直接选中
// TODO 考虑如何设置默认值,比如只有一个的,就直接选中
multiple
=
{
isMultiple
}
multiple
className=
{
styles
[
"
check-group
"
]
}
className=
{
styles
[
"
check-group
"
]
}
>
>
{
options
[
1
].
map
((
card
,
j
)
=>
(
{
options
[
1
].
map
((
card
,
j
)
=>
(
...
...
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