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
20ee2923
Commit
20ee2923
authored
Apr 02, 2023
by
Chunchi Che
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
optimize dragmodal code
parent
2ce5bffb
Pipeline
#21063
failed with stages
in 12 minutes and 59 seconds
Changes
9
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
137 additions
and
241 deletions
+137
-241
src/ui/Duel/checkCardModal.tsx
src/ui/Duel/checkCardModal.tsx
+29
-50
src/ui/Duel/checkCardModalV2.tsx
src/ui/Duel/checkCardModalV2.tsx
+15
-42
src/ui/Duel/checkCardModalV3.tsx
src/ui/Duel/checkCardModalV3.tsx
+12
-34
src/ui/Duel/checkCounterModal.tsx
src/ui/Duel/checkCounterModal.tsx
+9
-14
src/ui/Duel/dragModal.tsx
src/ui/Duel/dragModal.tsx
+7
-15
src/ui/Duel/optionModal.tsx
src/ui/Duel/optionModal.tsx
+18
-23
src/ui/Duel/positionModal.tsx
src/ui/Duel/positionModal.tsx
+18
-23
src/ui/Duel/sortCardModal.tsx
src/ui/Duel/sortCardModal.tsx
+5
-10
src/ui/Duel/yesNoModal.tsx
src/ui/Duel/yesNoModal.tsx
+24
-30
No files found.
src/ui/Duel/checkCardModal.tsx
View file @
20ee2923
import
React
,
{
use
Ref
,
use
State
}
from
"
react
"
;
import
React
,
{
useState
}
from
"
react
"
;
import
{
useAppSelector
}
from
"
../../hook
"
;
import
{
store
}
from
"
../../store
"
;
import
{
...
...
@@ -32,18 +32,7 @@ const CheckCardModal = () => {
const
cancelResponse
=
useAppSelector
(
selectCheckCardModalCacnelResponse
);
const
[
response
,
setResponse
]
=
useState
<
number
[]
>
([]);
const
defaultValue
:
number
[]
=
[];
// Draggable 相关
const
[
draggable
,
setDraggable
]
=
useState
(
false
);
const
draggleRef
=
useRef
<
HTMLDivElement
>
(
null
);
const
onMouseOver
=
()
=>
{
if
(
draggable
)
{
setDraggable
(
false
);
}
};
const
onMouseOut
=
()
=>
{
setDraggable
(
true
);
};
// TODO: 这里可以考虑更好地封装
const
sendResponseHandler
=
(
handlerName
:
string
|
undefined
,
...
...
@@ -65,11 +54,10 @@ const CheckCardModal = () => {
return
(
<
DragModal
modalProps=
{
{
title
:
`请选择${min}到${max}张卡片`
,
open
:
isOpen
,
closable
:
false
,
footer
:
(
title=
{
`请选择${min}到${max}张卡片`
}
open=
{
isOpen
}
closable=
{
false
}
footer=
{
<>
<
Button
disabled=
{
response
.
length
<
min
||
response
.
length
>
max
}
...
...
@@ -78,8 +66,6 @@ const CheckCardModal = () => {
dispatch
(
setCheckCardModalIsOpen
(
false
));
dispatch
(
resetCheckCardModal
());
}
}
onMouseOver=
{
onMouseOver
}
onMouseOut=
{
onMouseOut
}
onFocus=
{
()
=>
{}
}
onBlur=
{
()
=>
{}
}
>
...
...
@@ -94,8 +80,6 @@ const CheckCardModal = () => {
dispatch
(
setCheckCardModalIsOpen
(
false
));
dispatch
(
resetCheckCardModal
());
}
}
onMouseOver=
{
onMouseOver
}
onMouseOut=
{
onMouseOut
}
onFocus=
{
()
=>
{}
}
onBlur=
{
()
=>
{}
}
>
...
...
@@ -105,11 +89,8 @@ const CheckCardModal = () => {
<></>
)
}
</>
),
width
:
800
,
}
}
dragRef=
{
draggleRef
}
draggable=
{
draggable
}
}
width=
{
800
}
>
<
CheckCard
.
Group
multiple
...
...
@@ -146,8 +127,6 @@ const CheckCardModal = () => {
style=
{
{
width
:
100
}
}
/>
}
onMouseEnter=
{
onMouseOver
}
onMouseLeave=
{
onMouseOut
}
value=
{
option
.
response
}
/>
</
Popover
>
...
...
src/ui/Duel/checkCardModalV2.tsx
View file @
20ee2923
import
React
,
{
useRef
,
useState
}
from
"
react
"
;
import
React
from
"
react
"
;
import
{
useAppSelector
}
from
"
../../hook
"
;
import
{
store
}
from
"
../../store
"
;
import
{
Button
,
Card
,
Row
,
Col
}
from
"
antd
"
;
...
...
@@ -32,18 +32,7 @@ const CheckCardModalV2 = () => {
);
const
selectedOptions
=
useAppSelector
(
selectCheckCardModalV2SelectedOptions
);
const
responseable
=
useAppSelector
(
selectCheckCardModalV2ResponseAble
);
// Draggable 相关
const
[
draggable
,
setDraggable
]
=
useState
(
false
);
const
draggleRef
=
useRef
<
HTMLDivElement
>
(
null
);
const
onMouseOver
=
()
=>
{
if
(
draggable
)
{
setDraggable
(
false
);
}
};
const
onMouseOut
=
()
=>
{
setDraggable
(
true
);
};
const
onFinish
=
()
=>
{
sendSelectUnselectCardResponse
({
cancel_or_finish
:
true
});
dispatch
(
setCheckCardModalV2IsOpen
(
false
));
...
...
@@ -57,34 +46,20 @@ const CheckCardModalV2 = () => {
return
(
<
DragModal
modalProps=
{
{
title
:
`请选择未选择的卡片,最少${min}张,最多${max}张`
,
open
:
isOpen
,
closable
:
false
,
footer
:
(
title=
{
`请选择未选择的卡片,最少${min}张,最多${max}张`
}
open=
{
isOpen
}
closable=
{
false
}
footer=
{
<>
<
Button
disabled=
{
!
finishable
||
!
responseable
}
onClick=
{
onFinish
}
onMouseOver=
{
onMouseOver
}
onMouseOut=
{
onMouseOut
}
>
<
Button
disabled=
{
!
finishable
||
!
responseable
}
onClick=
{
onFinish
}
>
finish
</
Button
>
<
Button
disabled=
{
!
cancelable
||
!
responseable
}
onClick=
{
onCancel
}
onMouseOver=
{
onMouseOver
}
onMouseOut=
{
onMouseOut
}
>
<
Button
disabled=
{
!
cancelable
||
!
responseable
}
onClick=
{
onCancel
}
>
cancel
</
Button
>
</>
),
width
:
800
,
}
}
dragRef=
{
draggleRef
}
draggable=
{
draggable
}
}
width=
{
800
}
>
<
CheckCard
.
Group
bordered
...
...
@@ -114,8 +89,6 @@ const CheckCardModalV2 = () => {
/>
}
value=
{
option
.
response
}
onMouseEnter=
{
onMouseOver
}
onMouseLeave=
{
onMouseOut
}
/>
</
Col
>
);
...
...
src/ui/Duel/checkCardModalV3.tsx
View file @
20ee2923
import
React
,
{
use
Ref
,
use
State
}
from
"
react
"
;
import
React
,
{
useState
}
from
"
react
"
;
import
{
useAppSelector
}
from
"
../../hook
"
;
import
{
store
}
from
"
../../store
"
;
import
{
Button
,
Card
,
Row
,
Col
}
from
"
antd
"
;
...
...
@@ -32,18 +32,7 @@ const CheckCardModalV3 = () => {
.
concat
(
selectedOptions
)
.
map
((
option
)
=>
option
.
level2
)
.
reduce
((
sum
,
current
)
=>
sum
+
current
,
0
);
// Draggable 相关
const
[
draggable
,
setDraggable
]
=
useState
(
false
);
const
draggleRef
=
useRef
<
HTMLDivElement
>
(
null
);
const
onMouseOver
=
()
=>
{
if
(
draggable
)
{
setDraggable
(
false
);
}
};
const
onMouseOut
=
()
=>
{
setDraggable
(
true
);
};
const
responseable
=
(
overflow
?
Level1Sum
>=
LevelSum
||
Level2Sum
>=
LevelSum
...
...
@@ -61,26 +50,17 @@ const CheckCardModalV3 = () => {
return
(
<
DragModal
modalProps=
{
{
title
:
`请选择卡片,最少${min}张,最多${max}张`
,
open
:
isOpen
,
closable
:
false
,
footer
:
(
title=
{
`请选择卡片,最少${min}张,最多${max}张`
}
open=
{
isOpen
}
closable=
{
false
}
footer=
{
<>
<
Button
disabled=
{
!
responseable
}
onClick=
{
onFinish
}
onMouseOver=
{
onMouseOver
}
onMouseOut=
{
onMouseOut
}
>
<
Button
disabled=
{
!
responseable
}
onClick=
{
onFinish
}
>
finish
</
Button
>
</>
),
width
:
800
,
}
}
dragRef=
{
draggleRef
}
draggable=
{
draggable
}
}
width=
{
800
}
>
<
CheckCard
.
Group
bordered
...
...
@@ -107,8 +87,6 @@ const CheckCardModalV3 = () => {
/>
}
value=
{
option
}
onMouseEnter=
{
onMouseOver
}
onMouseLeave=
{
onMouseOut
}
/>
</
Col
>
);
...
...
src/ui/Duel/checkCounterModal.tsx
View file @
20ee2923
import
{
Button
,
Row
,
Col
,
Card
,
InputNumber
}
from
"
antd
"
;
import
React
,
{
use
Ref
,
use
State
}
from
"
react
"
;
import
React
,
{
useState
}
from
"
react
"
;
import
{
sendSelectCounterResponse
}
from
"
../../api/ocgcore/ocgHelper
"
;
import
{
fetchStrings
}
from
"
../../api/strings
"
;
import
{
useAppSelector
}
from
"
../../hook
"
;
...
...
@@ -19,7 +19,6 @@ const CheckCounterModal = () => {
const
[
selected
,
setSelected
]
=
useState
(
new
Array
(
options
.
length
));
const
sum
=
selected
.
reduce
((
sum
,
current
)
=>
sum
+
current
,
0
);
const
finishable
=
sum
==
min
;
const
draggleRef
=
useRef
<
HTMLDivElement
>
(
null
);
const
onFinish
=
()
=>
{
sendSelectCounterResponse
(
selected
);
...
...
@@ -28,18 +27,14 @@ const CheckCounterModal = () => {
return
(
<
DragModal
modalProps=
{
{
title
:
`请移除${min}个${counterName}`
,
open
:
isOpen
,
closable
:
false
,
footer
:
(
title=
{
`请移除${min}个${counterName}`
}
open=
{
isOpen
}
closable=
{
false
}
footer=
{
<
Button
disabled=
{
!
finishable
}
onClick=
{
onFinish
}
>
finish
</
Button
>
),
}
}
dragRef=
{
draggleRef
}
draggable=
{
true
}
}
>
<
Row
>
{
options
.
map
((
option
,
idx
)
=>
{
...
...
src/ui/Duel/dragModal.tsx
View file @
20ee2923
// 经过封装的可拖拽`Modal`
import
React
,
{
useState
}
from
"
react
"
;
import
React
,
{
use
Ref
,
use
State
}
from
"
react
"
;
import
type
{
DraggableData
,
DraggableEvent
}
from
"
react-draggable
"
;
import
Draggable
from
"
react-draggable
"
;
import
{
Modal
,
ModalProps
}
from
"
antd
"
;
export
interface
DragModalProps
{
modalProps
:
ModalProps
;
dragRef
:
React
.
RefObject
<
HTMLDivElement
>
;
draggable
:
boolean
;
children
?:
React
.
ReactNode
;
}
export
interface
DragModalProps
extends
ModalProps
{}
const
DragModal
=
(
props
:
DragModalProps
)
=>
{
const
dragRef
=
useRef
<
HTMLDivElement
>
(
null
);
const
[
bounds
,
setBounds
]
=
useState
({
left
:
0
,
top
:
0
,
...
...
@@ -20,7 +16,7 @@ const DragModal = (props: DragModalProps) => {
});
const
onStart
=
(
_event
:
DraggableEvent
,
uiData
:
DraggableData
)
=>
{
const
{
clientWidth
,
clientHeight
}
=
window
.
document
.
documentElement
;
const
targetRect
=
props
.
dragRef
.
current
?.
getBoundingClientRect
();
const
targetRect
=
dragRef
.
current
?.
getBoundingClientRect
();
if
(
!
targetRect
)
{
return
;
}
...
...
@@ -34,14 +30,10 @@ const DragModal = (props: DragModalProps) => {
return
(
<
Modal
{
...
props
.
modalProps
}
{
...
props
}
modalRender=
{
(
modal
)
=>
(
<
Draggable
disabled=
{
!
props
.
draggable
}
bounds=
{
bounds
}
onStart=
{
onStart
}
>
<
div
ref=
{
props
.
dragRef
}
>
{
modal
}
</
div
>
<
Draggable
bounds=
{
bounds
}
onStart=
{
onStart
}
>
<
div
ref=
{
dragRef
}
>
{
modal
}
</
div
>
</
Draggable
>
)
}
>
...
...
src/ui/Duel/optionModal.tsx
View file @
20ee2923
import
React
,
{
use
Ref
,
use
State
}
from
"
react
"
;
import
React
,
{
useState
}
from
"
react
"
;
import
{
useAppSelector
}
from
"
../../hook
"
;
import
{
store
}
from
"
../../store
"
;
import
{
Button
}
from
"
antd
"
;
...
...
@@ -19,15 +19,13 @@ const OptionModal = () => {
const
isOpen
=
useAppSelector
(
selectOptionModalIsOpen
);
const
options
=
useAppSelector
(
selectOptionModalOptions
);
const
[
selected
,
setSelected
]
=
useState
<
number
|
undefined
>
(
undefined
);
const
draggleRef
=
useRef
<
HTMLDivElement
>
(
null
);
return
(
<
DragModal
modalProps=
{
{
title
:
"
请选择需要发动的效果
"
,
open
:
isOpen
,
closable
:
false
,
footer
:
(
title=
"请选择需要发动的效果"
open=
{
isOpen
}
closable=
{
false
}
footer=
{
<
Button
disabled=
{
selected
===
undefined
}
onClick=
{
()
=>
{
...
...
@@ -40,10 +38,7 @@ const OptionModal = () => {
>
submit
</
Button
>
),
}
}
dragRef=
{
draggleRef
}
draggable=
{
true
}
}
>
<
CheckCard
.
Group
bordered
...
...
src/ui/Duel/positionModal.tsx
View file @
20ee2923
import
React
,
{
use
Ref
,
use
State
}
from
"
react
"
;
import
React
,
{
useState
}
from
"
react
"
;
import
{
useAppSelector
}
from
"
../../hook
"
;
import
{
store
}
from
"
../../store
"
;
import
{
Button
}
from
"
antd
"
;
...
...
@@ -22,15 +22,13 @@ const PositionModal = () => {
const
[
selected
,
setSelected
]
=
useState
<
ygopro
.
CardPosition
|
undefined
>
(
undefined
);
const
draggleRef
=
useRef
<
HTMLDivElement
>
(
null
);
return
(
<
DragModal
modalProps=
{
{
title
:
"
请选择表示形式
"
,
open
:
isOpen
,
closable
:
false
,
footer
:
(
title=
"请选择表示形式"
open=
{
isOpen
}
closable=
{
false
}
footer=
{
<
Button
disabled=
{
selected
===
undefined
}
onClick=
{
()
=>
{
...
...
@@ -43,10 +41,7 @@ const PositionModal = () => {
>
submit
</
Button
>
),
}
}
dragRef=
{
draggleRef
}
draggable=
{
true
}
}
>
<
CheckCard
.
Group
bordered
...
...
src/ui/Duel/sortCardModal.tsx
View file @
20ee2923
import
React
,
{
useEffect
,
use
Ref
,
use
State
}
from
"
react
"
;
import
React
,
{
useEffect
,
useState
}
from
"
react
"
;
import
{
DndContext
,
closestCenter
,
...
...
@@ -38,7 +38,6 @@ const SortCardModal = () => {
coordinateGetter
:
sortableKeyboardCoordinates
,
})
);
const
draggleRef
=
useRef
<
HTMLDivElement
>
(
null
);
const
onFinish
=
()
=>
{
sendSortCardResponse
(
items
.
map
((
item
)
=>
item
.
response
));
...
...
@@ -63,14 +62,10 @@ const SortCardModal = () => {
return
(
<
DragModal
modalProps=
{
{
title
:
"
请为下列卡牌排序
"
,
open
:
isOpen
,
closable
:
false
,
footer
:
<
Button
onClick=
{
onFinish
}
>
finish
</
Button
>,
}
}
dragRef=
{
draggleRef
}
draggable=
{
false
}
title=
"请为下列卡牌排序"
open=
{
isOpen
}
closable=
{
false
}
footer=
{
<
Button
onClick=
{
onFinish
}
>
finish
</
Button
>
}
>
<
DndContext
sensors=
{
sensors
}
...
...
src/ui/Duel/yesNoModal.tsx
View file @
20ee2923
import
React
,
{
useRef
}
from
"
react
"
;
import
React
from
"
react
"
;
import
{
useAppSelector
}
from
"
../../hook
"
;
import
{
store
}
from
"
../../store
"
;
import
{
Button
}
from
"
antd
"
;
...
...
@@ -14,16 +14,13 @@ const YesNoModal = () => {
const
dispatch
=
store
.
dispatch
;
const
isOpen
=
useAppSelector
(
selectYesNoModalIsOpen
);
const
msg
=
useAppSelector
(
selectYesNOModalMsg
);
// Draggable 相关
const
draggleRef
=
useRef
<
HTMLDivElement
>
(
null
);
return
(
<
DragModal
modalProps=
{
{
title
:
msg
,
open
:
isOpen
,
closable
:
false
,
footer
:
(
title=
{
msg
}
open=
{
isOpen
}
closable=
{
false
}
footer=
{
<>
<
Button
onClick=
{
()
=>
{
...
...
@@ -42,10 +39,7 @@ const YesNoModal = () => {
No
</
Button
>
</>
),
}
}
dragRef=
{
draggleRef
}
draggable=
{
true
}
}
/>
);
};
...
...
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