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
41c6c3c2
Commit
41c6c3c2
authored
Aug 30, 2023
by
Chunchi Che
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move DeckZone and DeckCard to Shared
parent
fed1294e
Pipeline
#23296
failed with stages
in 15 minutes and 48 seconds
Changes
11
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
253 additions
and
203 deletions
+253
-203
src/ui/BuildDeck/index.module.scss
src/ui/BuildDeck/index.module.scss
+1
-66
src/ui/BuildDeck/index.tsx
src/ui/BuildDeck/index.tsx
+5
-131
src/ui/BuildDeck/store.ts
src/ui/BuildDeck/store.ts
+2
-1
src/ui/BuildDeck/utils.ts
src/ui/BuildDeck/utils.ts
+0
-2
src/ui/NewSide/index.module.scss
src/ui/NewSide/index.module.scss
+1
-0
src/ui/NewSide/index.tsx
src/ui/NewSide/index.tsx
+20
-3
src/ui/Shared/DeckCard/index.module.scss
src/ui/Shared/DeckCard/index.module.scss
+38
-0
src/ui/Shared/DeckCard/index.tsx
src/ui/Shared/DeckCard/index.tsx
+56
-0
src/ui/Shared/DeckZone/index.module.scss
src/ui/Shared/DeckZone/index.module.scss
+39
-0
src/ui/Shared/DeckZone/index.tsx
src/ui/Shared/DeckZone/index.tsx
+89
-0
src/ui/Shared/index.ts
src/ui/Shared/index.ts
+2
-0
No files found.
src/ui/BuildDeck/index.module.scss
View file @
41c6c3c2
...
@@ -57,33 +57,7 @@
...
@@ -57,33 +57,7 @@
display
:
flex
;
display
:
flex
;
flex-direction
:
column
;
flex-direction
:
column
;
height
:
100%
;
height
:
100%
;
}
--card-grid
:
10
;
.main
,
.extra
,
.side
{
transition
:
0
.2s
;
position
:
relative
;
border-bottom
:
1px
solid
rgba
(
255
,
255
,
255
,
0
.1
);
padding
:
0
.75rem
;
&
.over
{
background-color
:
hsla
(
0
,
0%
,
100%
,
0
.05
);
}
&
.not-allow-to-drop
{
background-color
:
rgba
(
255
,
0
,
0
,
0
.15
);
cursor
:
not
-
allowed
;
}
}
.main
{
flex
:
3
;
}
.extra
,
.side
{
flex
:
1
;
}
.card-continer
{
display
:
grid
;
grid-template-columns
:
repeat
(
10
,
1fr
);
gap
:
5px
;
}
}
background-color
:
hsla
(
0
,
0%
,
100%
,
0
.05
);
background-color
:
hsla
(
0
,
0%
,
100%
,
0
.05
);
backdrop-filter
:
blur
(
5px
);
backdrop-filter
:
blur
(
5px
);
...
@@ -98,45 +72,6 @@
...
@@ -98,45 +72,6 @@
border-radius
:
0
var
(
--
border-radius
)
var
(
--
border-radius
)
0
;
border-radius
:
0
var
(
--
border-radius
)
var
(
--
border-radius
)
0
;
}
}
.card
{
cursor
:
move
;
width
:
100%
;
background-color
:
rgba
(
255
,
255
,
255
,
0
.1
);
aspect-ratio
:
var
(
--
card-ratio
);
position
:
relative
;
background-size
:
contain
;
content-visibility
:
auto
;
transition
:
0
.1s
;
&
:hover
{
filter
:
brightness
(
0
.9
);
}
.cardname
{
font-size
:
12px
;
position
:
absolute
;
padding
:
5px
;
top
:
0
;
bottom
:
0
;
max-height
:
100%
;
margin
:
auto
;
left
:
0
;
height
:
fit-content
;
width
:
100%
;
text-align
:
center
;
line-height
:
1
.75em
;
overflow
:
hidden
;
//超出的文本隐藏
text-overflow
:
ellipsis
;
//溢出用省略号显示
}
.cardcover
{
position
:
relative
;
}
.cardlimit
{
position
:
absolute
;
top
:
2px
;
left
:
2px
;
width
:
20px
;
}
}
.search-cards-container
{
.search-cards-container
{
height
:
100%
;
height
:
100%
;
.search-cards
{
.search-cards
{
...
...
src/ui/BuildDeck/index.tsx
View file @
41c6c3c2
...
@@ -16,28 +16,28 @@ import {
...
@@ -16,28 +16,28 @@ import {
Pagination
,
Pagination
,
Space
,
Space
,
}
from
"
antd
"
;
}
from
"
antd
"
;
import
classNames
from
"
classnames
"
;
import
{
isEqual
}
from
"
lodash-es
"
;
import
{
isEqual
}
from
"
lodash-es
"
;
import
{
type
OverlayScrollbarsComponentRef
}
from
"
overlayscrollbars-react
"
;
import
{
type
OverlayScrollbarsComponentRef
}
from
"
overlayscrollbars-react
"
;
import
{
memo
,
useCallback
,
useEffect
,
useRef
,
useState
}
from
"
react
"
;
import
{
memo
,
useCallback
,
useEffect
,
useRef
,
useState
}
from
"
react
"
;
import
{
DndProvider
,
useDr
ag
,
useDr
op
}
from
"
react-dnd
"
;
import
{
DndProvider
,
useDrop
}
from
"
react-dnd
"
;
import
{
HTML5Backend
}
from
"
react-dnd-html5-backend
"
;
import
{
HTML5Backend
}
from
"
react-dnd-html5-backend
"
;
import
{
LoaderFunction
}
from
"
react-router-dom
"
;
import
{
LoaderFunction
}
from
"
react-router-dom
"
;
import
{
proxy
,
useSnapshot
}
from
"
valtio
"
;
import
{
proxy
,
useSnapshot
}
from
"
valtio
"
;
import
{
subscribeKey
}
from
"
valtio/utils
"
;
import
{
subscribeKey
}
from
"
valtio/utils
"
;
import
{
type
CardMeta
,
forbidden
,
searchCards
}
from
"
@/api
"
;
import
{
type
CardMeta
,
searchCards
}
from
"
@/api
"
;
import
{
isToken
}
from
"
@/common
"
;
import
{
isToken
}
from
"
@/common
"
;
import
{
useConfig
}
from
"
@/config
"
;
import
{
FtsConditions
}
from
"
@/middleware/sqlite/fts
"
;
import
{
FtsConditions
}
from
"
@/middleware/sqlite/fts
"
;
import
{
deckStore
,
type
IDeck
,
initStore
}
from
"
@/stores
"
;
import
{
deckStore
,
type
IDeck
,
initStore
}
from
"
@/stores
"
;
import
{
import
{
Background
,
Background
,
DeckCard
,
DeckZone
,
IconFont
,
IconFont
,
Loading
,
Loading
,
ScrollableArea
,
ScrollableArea
,
YgoCard
,
}
from
"
@/ui/Shared
"
;
}
from
"
@/ui/Shared
"
;
import
{
Type
}
from
"
@/ui/Shared/DeckZone
"
;
import
{
CardDetail
}
from
"
./CardDetail
"
;
import
{
CardDetail
}
from
"
./CardDetail
"
;
import
{
DeckSelect
}
from
"
./DeckSelect
"
;
import
{
DeckSelect
}
from
"
./DeckSelect
"
;
...
@@ -49,11 +49,8 @@ import {
...
@@ -49,11 +49,8 @@ import {
downloadDeckAsYDK
,
downloadDeckAsYDK
,
editingDeckToIDeck
,
editingDeckToIDeck
,
iDeckToEditingDeck
,
iDeckToEditingDeck
,
type
Type
,
}
from
"
./utils
"
;
}
from
"
./utils
"
;
const
{
assetsPath
}
=
useConfig
();
export
const
loader
:
LoaderFunction
=
async
()
=>
{
export
const
loader
:
LoaderFunction
=
async
()
=>
{
// 必须先加载卡组,不然页面会崩溃
// 必须先加载卡组,不然页面会崩溃
if
(
!
initStore
.
decks
)
{
if
(
!
initStore
.
decks
)
{
...
@@ -410,84 +407,6 @@ const Search: React.FC = () => {
...
@@ -410,84 +407,6 @@ const Search: React.FC = () => {
);
);
};
};
/** 正在组卡的zone,包括main/extra/side */
const
DeckZone
:
React
.
FC
<
{
type
:
Type
;
cards
:
CardMeta
[];
canAdd
:
(
card
:
CardMeta
,
type
:
Type
,
source
:
Type
|
"
search
"
,
)
=>
{
result
:
boolean
;
reason
:
string
};
onChange
:
(
card
:
CardMeta
,
source
:
Type
|
"
search
"
,
destination
:
Type
,
)
=>
void
;
onElementClick
:
(
card
:
CardMeta
)
=>
void
;
onElementRightClick
:
(
card
:
CardMeta
)
=>
void
;
}
>
=
({
type
,
cards
,
canAdd
,
onChange
,
onElementClick
,
onElementRightClick
,
})
=>
{
const
{
message
}
=
App
.
useApp
();
const
[
allowToDrop
,
setAllowToDrop
]
=
useState
(
false
);
const
[{
isOver
},
dropRef
]
=
useDrop
({
accept
:
[
"
Card
"
],
// 指明该区域允许接收的拖放物。可以是单个,也可以是数组
// 里面的值就是useDrag所定义的type
// 当拖拽物在这个拖放区域放下时触发,这个item就是拖拽物的item(拖拽物携带的数据)
drop
:
({
value
,
source
}:
{
value
:
CardMeta
;
source
:
Type
|
"
search
"
})
=>
{
if
(
type
===
source
)
return
;
const
{
result
,
reason
}
=
canAdd
(
value
,
type
,
source
);
if
(
result
)
{
onChange
(
value
,
source
,
type
);
}
else
{
message
.
error
(
reason
);
}
},
hover
:
({
value
,
source
})
=>
{
setAllowToDrop
(
type
!==
source
?
canAdd
(
value
,
type
,
source
).
result
:
true
,
);
},
collect
:
(
monitor
)
=>
({
isOver
:
monitor
.
isOver
(),
}),
});
return
(
<
div
className=
{
classNames
(
styles
[
type
],
{
[
styles
.
over
]:
isOver
,
[
styles
[
"
not-allow-to-drop
"
]]:
isOver
&&
!
allowToDrop
,
})
}
ref=
{
dropRef
}
>
<
div
className=
{
styles
[
"
card-continer
"
]
}
>
{
cards
.
map
((
card
,
i
)
=>
(
<
DeckCard
value=
{
card
}
key=
{
card
.
id
+
i
+
type
}
source=
{
type
}
onClick=
{
()
=>
{
onElementClick
(
card
);
}
}
onRightClick=
{
()
=>
{
onElementRightClick
(
card
);
}
}
/>
))
}
<
div
className=
{
styles
[
"
editing-zone-name
"
]
}
>
{
`${type.toUpperCase()}: ${cards.length}`
}
</
div
>
</
div
>
</
div
>
);
};
/** 搜索区的搜索结果,使用memo避免重复渲染 */
/** 搜索区的搜索结果,使用memo避免重复渲染 */
const
SearchResults
:
React
.
FC
<
{
const
SearchResults
:
React
.
FC
<
{
results
:
CardMeta
[];
results
:
CardMeta
[];
...
@@ -539,51 +458,6 @@ const SearchResults: React.FC<{
...
@@ -539,51 +458,6 @@ const SearchResults: React.FC<{
);
);
});
});
/** 本组件内使用的单张卡片,增加了文字在图片下方 */
export
const
DeckCard
:
React
.
FC
<
{
value
:
CardMeta
;
source
:
Type
|
"
search
"
;
onRightClick
?:
()
=>
void
;
onClick
?:
()
=>
void
;
}
>
=
memo
(({
value
,
source
,
onRightClick
,
onClick
})
=>
{
const
ref
=
useRef
<
HTMLDivElement
>
(
null
);
const
[{
isDragging
},
drag
]
=
useDrag
({
type
:
"
Card
"
,
item
:
{
value
,
source
},
collect
:
(
monitor
)
=>
({
isDragging
:
monitor
.
isDragging
(),
}),
});
drag
(
ref
);
const
[
showText
,
setShowText
]
=
useState
(
true
);
const
limitCnt
=
forbidden
.
get
(
value
.
id
);
return
(
<
div
className=
{
styles
.
card
}
ref=
{
ref
}
style=
{
{
opacity
:
isDragging
&&
source
!==
"
search
"
?
0
:
1
}
}
onClick=
{
onClick
}
onContextMenu=
{
(
e
)
=>
{
e
.
preventDefault
();
onRightClick
?.();
}
}
>
{
showText
&&
<
div
className=
{
styles
.
cardname
}
>
{
value
.
text
.
name
}
</
div
>
}
<
YgoCard
className=
{
styles
.
cardcover
}
code=
{
value
.
id
}
onLoad=
{
()
=>
setShowText
(
false
)
}
/>
{
limitCnt
!==
undefined
&&
(
<
img
className=
{
styles
.
cardlimit
}
src=
{
`${assetsPath}/Limit0${limitCnt}.png`
}
/>
)
}
</
div
>
);
});
const
HigherCardDetail
:
React
.
FC
=
()
=>
{
const
HigherCardDetail
:
React
.
FC
=
()
=>
{
const
{
id
,
open
}
=
useSnapshot
(
selectedCard
);
const
{
id
,
open
}
=
useSnapshot
(
selectedCard
);
return
(
return
(
...
...
src/ui/BuildDeck/store.ts
View file @
41c6c3c2
...
@@ -2,8 +2,9 @@ import { proxy } from "valtio";
...
@@ -2,8 +2,9 @@ import { proxy } from "valtio";
import
{
type
CardMeta
}
from
"
@/api
"
;
import
{
type
CardMeta
}
from
"
@/api
"
;
import
{
isExtraDeckCard
,
isToken
}
from
"
@/common
"
;
import
{
isExtraDeckCard
,
isToken
}
from
"
@/common
"
;
import
{
Type
}
from
"
@/ui/Shared/DeckZone
"
;
import
{
compareCards
,
type
EditingDeck
,
type
Type
}
from
"
./utils
"
;
import
{
compareCards
,
type
EditingDeck
}
from
"
./utils
"
;
export
const
editDeckStore
=
proxy
({
export
const
editDeckStore
=
proxy
({
deckName
:
""
,
deckName
:
""
,
...
...
src/ui/BuildDeck/utils.ts
View file @
41c6c3c2
...
@@ -2,8 +2,6 @@ import { type CardMeta, fetchCard } from "@/api";
...
@@ -2,8 +2,6 @@ import { type CardMeta, fetchCard } from "@/api";
import
{
tellCardBasicType
,
tellCardSecondaryType
}
from
"
@/common
"
;
import
{
tellCardBasicType
,
tellCardSecondaryType
}
from
"
@/common
"
;
import
{
type
IDeck
}
from
"
@/stores
"
;
import
{
type
IDeck
}
from
"
@/stores
"
;
export
type
Type
=
"
main
"
|
"
extra
"
|
"
side
"
;
/** 用在卡组编辑 */
/** 用在卡组编辑 */
export
interface
EditingDeck
{
export
interface
EditingDeck
{
deckName
:
string
;
deckName
:
string
;
...
...
src/ui/NewSide/index.module.scss
View file @
41c6c3c2
...
@@ -41,6 +41,7 @@
...
@@ -41,6 +41,7 @@
display
:
flex
;
display
:
flex
;
flex-direction
:
column
;
flex-direction
:
column
;
height
:
100%
;
height
:
100%
;
--card-grid
:
15
;
}
}
background-color
:
hsla
(
0
,
0%
,
100%
,
0
.05
);
background-color
:
hsla
(
0
,
0%
,
100%
,
0
.05
);
backdrop-filter
:
blur
(
5px
);
backdrop-filter
:
blur
(
5px
);
...
...
src/ui/NewSide/index.tsx
View file @
41c6c3c2
import
{
CheckOutlined
,
UndoOutlined
}
from
"
@ant-design/icons
"
;
import
{
CheckOutlined
,
UndoOutlined
}
from
"
@ant-design/icons
"
;
import
{
Button
,
Space
}
from
"
antd
"
;
import
{
Button
,
Space
}
from
"
antd
"
;
import
React
from
"
react
"
;
import
React
,
{
useState
}
from
"
react
"
;
import
{
DndProvider
}
from
"
react-dnd
"
;
import
{
DndProvider
}
from
"
react-dnd
"
;
import
{
HTML5Backend
}
from
"
react-dnd-html5-backend
"
;
import
{
HTML5Backend
}
from
"
react-dnd-html5-backend
"
;
import
{
fetchCard
}
from
"
@/api
"
;
import
{
deckStore
,
IDeck
}
from
"
@/stores
"
;
import
{
CardDetail
}
from
"
../BuildDeck/CardDetail
"
;
import
{
CardDetail
}
from
"
../BuildDeck/CardDetail
"
;
import
{
Background
,
ScrollableArea
}
from
"
../Shared
"
;
import
{
Background
,
DeckZone
,
ScrollableArea
}
from
"
../Shared
"
;
import
{
Chat
}
from
"
../WaitRoom/Chat
"
;
import
{
Chat
}
from
"
../WaitRoom/Chat
"
;
import
styles
from
"
./index.module.scss
"
;
import
styles
from
"
./index.module.scss
"
;
export
const
Component
:
React
.
FC
=
()
=>
{
export
const
Component
:
React
.
FC
=
()
=>
{
const
[
deck
,
setDeck
]
=
useState
<
IDeck
>
({
...
deckStore
.
decks
[
0
]
});
return
(
return
(
<
DndProvider
backend=
{
HTML5Backend
}
>
<
DndProvider
backend=
{
HTML5Backend
}
>
<
Background
/>
<
Background
/>
...
@@ -30,7 +34,20 @@ export const Component: React.FC = () => {
...
@@ -30,7 +34,20 @@ export const Component: React.FC = () => {
</
Button
>
</
Button
>
</
Space
>
</
Space
>
</
Space
>
</
Space
>
<
ScrollableArea
className=
{
styles
[
"
deck-zone
"
]
}
></
ScrollableArea
>
<
ScrollableArea
className=
{
styles
[
"
deck-zone
"
]
}
>
{
([
"
main
"
,
"
extra
"
,
"
side
"
]
as
const
).
map
((
type
)
=>
(
<
DeckZone
key=
{
type
}
type=
{
type
}
cards=
{
[...
deck
[
type
]].
map
((
id
)
=>
fetchCard
(
id
))
}
canAdd=
{
(
card
,
type
,
source
)
=>
{
return
{
result
:
true
,
reason
:
""
};
}
}
onChange=
{
(
card
,
source
,
destination
)
=>
{}
}
onElementClick=
{
(
card
)
=>
{}
}
/>
))
}
</
ScrollableArea
>
</
div
>
</
div
>
</
div
>
</
div
>
<
div
className=
{
styles
[
"
detail-container
"
]
}
>
<
div
className=
{
styles
[
"
detail-container
"
]
}
>
...
...
src/ui/Shared/DeckCard/index.module.scss
0 → 100644
View file @
41c6c3c2
.card
{
cursor
:
move
;
width
:
100%
;
background-color
:
rgba
(
255
,
255
,
255
,
0
.1
);
aspect-ratio
:
var
(
--
card-ratio
);
position
:
relative
;
background-size
:
contain
;
content-visibility
:
auto
;
transition
:
0
.1s
;
&
:hover
{
filter
:
brightness
(
0
.9
);
}
.cardname
{
font-size
:
12px
;
position
:
absolute
;
padding
:
5px
;
top
:
0
;
bottom
:
0
;
max-height
:
100%
;
margin
:
auto
;
left
:
0
;
height
:
fit-content
;
width
:
100%
;
text-align
:
center
;
line-height
:
1
.75em
;
overflow
:
hidden
;
//超出的文本隐藏
text-overflow
:
ellipsis
;
//溢出用省略号显示
}
.cardcover
{
position
:
relative
;
}
.cardlimit
{
position
:
absolute
;
top
:
2px
;
left
:
2px
;
width
:
20px
;
}
}
src/ui/Shared/DeckCard/index.tsx
0 → 100644
View file @
41c6c3c2
import
React
,
{
memo
,
useRef
,
useState
}
from
"
react
"
;
import
{
useDrag
}
from
"
react-dnd
"
;
import
{
CardMeta
,
forbidden
}
from
"
@/api
"
;
import
{
useConfig
}
from
"
@/config
"
;
import
{
Type
}
from
"
../DeckZone
"
;
import
{
YgoCard
}
from
"
../YgoCard
"
;
import
styles
from
"
./index.module.scss
"
;
const
{
assetsPath
}
=
useConfig
();
/** 组卡页和Side页使用的单张卡片,增加了文字和禁限数量 */
export
const
DeckCard
:
React
.
FC
<
{
value
:
CardMeta
;
source
:
Type
|
"
search
"
;
onRightClick
?:
()
=>
void
;
onClick
?:
()
=>
void
;
}
>
=
memo
(({
value
,
source
,
onRightClick
,
onClick
})
=>
{
const
ref
=
useRef
<
HTMLDivElement
>
(
null
);
const
[{
isDragging
},
drag
]
=
useDrag
({
type
:
"
Card
"
,
item
:
{
value
,
source
},
collect
:
(
monitor
)
=>
({
isDragging
:
monitor
.
isDragging
(),
}),
});
drag
(
ref
);
const
[
showText
,
setShowText
]
=
useState
(
true
);
const
limitCnt
=
forbidden
.
get
(
value
.
id
);
return
(
<
div
className=
{
styles
.
card
}
ref=
{
ref
}
style=
{
{
opacity
:
isDragging
&&
source
!==
"
search
"
?
0
:
1
}
}
onClick=
{
onClick
}
onContextMenu=
{
(
e
)
=>
{
e
.
preventDefault
();
onRightClick
?.();
}
}
>
{
showText
&&
<
div
className=
{
styles
.
cardname
}
>
{
value
.
text
.
name
}
</
div
>
}
<
YgoCard
className=
{
styles
.
cardcover
}
code=
{
value
.
id
}
onLoad=
{
()
=>
setShowText
(
false
)
}
/>
{
limitCnt
!==
undefined
&&
(
<
img
className=
{
styles
.
cardlimit
}
src=
{
`${assetsPath}/Limit0${limitCnt}.png`
}
/>
)
}
</
div
>
);
});
src/ui/Shared/DeckZone/index.module.scss
0 → 100644
View file @
41c6c3c2
.main
,
.extra
,
.side
{
transition
:
0
.2s
;
position
:
relative
;
border-bottom
:
1px
solid
rgba
(
255
,
255
,
255
,
0
.1
);
padding
:
0
.75rem
;
&
.over
{
background-color
:
hsla
(
0
,
0%
,
100%
,
0
.05
);
}
&
.not-allow-to-drop
{
background-color
:
rgba
(
255
,
0
,
0
,
0
.15
);
cursor
:
not
-
allowed
;
}
}
.main
{
flex
:
3
;
}
.extra
,
.side
{
flex
:
1
;
}
.card-continer
{
display
:
grid
;
grid-template-columns
:
repeat
(
var
(
--
card-grid
)
,
1fr
);
gap
:
5px
;
}
.editing-zone-name
{
position
:
absolute
;
right
:
0
;
bottom
:
0
;
background-color
:
#212332
;
color
:
hsla
(
0
,
0%
,
100%
,
0
.3
);
font-size
:
12px
;
padding
:
2px
6px
;
font-family
:
var
(
--
theme-font
);
user-select
:
none
;
}
src/ui/Shared/DeckZone/index.tsx
0 → 100644
View file @
41c6c3c2
import
{
App
}
from
"
antd
"
;
import
classNames
from
"
classnames
"
;
import
React
,
{
useState
}
from
"
react
"
;
import
{
useDrop
}
from
"
react-dnd
"
;
import
{
CardMeta
}
from
"
@/api
"
;
import
{
DeckCard
}
from
"
../DeckCard
"
;
import
styles
from
"
./index.module.scss
"
;
/** 正在组卡的zone,包括main/extra/side
* 该组件内部没有引用任何store,是解耦的*/
export
type
Type
=
"
main
"
|
"
extra
"
|
"
side
"
;
export
const
DeckZone
:
React
.
FC
<
{
type
:
Type
;
cards
:
CardMeta
[];
canAdd
:
(
card
:
CardMeta
,
type
:
Type
,
source
:
Type
|
"
search
"
,
)
=>
{
result
:
boolean
;
reason
:
string
};
onChange
:
(
card
:
CardMeta
,
source
:
Type
|
"
search
"
,
destination
:
Type
,
)
=>
void
;
onElementClick
:
(
card
:
CardMeta
)
=>
void
;
onElementRightClick
?:
(
card
:
CardMeta
)
=>
void
;
}
>
=
({
type
,
cards
,
canAdd
,
onChange
,
onElementClick
,
onElementRightClick
,
})
=>
{
const
{
message
}
=
App
.
useApp
();
const
[
allowToDrop
,
setAllowToDrop
]
=
useState
(
false
);
const
[{
isOver
},
dropRef
]
=
useDrop
({
accept
:
[
"
Card
"
],
// 指明该区域允许接收的拖放物。可以是单个,也可以是数组
// 里面的值就是useDrag所定义的type
// 当拖拽物在这个拖放区域放下时触发,这个item就是拖拽物的item(拖拽物携带的数据)
drop
:
({
value
,
source
}:
{
value
:
CardMeta
;
source
:
Type
|
"
search
"
})
=>
{
if
(
type
===
source
)
return
;
const
{
result
,
reason
}
=
canAdd
(
value
,
type
,
source
);
if
(
result
)
{
onChange
(
value
,
source
,
type
);
}
else
{
message
.
error
(
reason
);
}
},
hover
:
({
value
,
source
})
=>
{
setAllowToDrop
(
type
!==
source
?
canAdd
(
value
,
type
,
source
).
result
:
true
,
);
},
collect
:
(
monitor
)
=>
({
isOver
:
monitor
.
isOver
(),
}),
});
return
(
<
div
className=
{
classNames
(
styles
[
type
],
{
[
styles
.
over
]:
isOver
,
[
styles
[
"
not-allow-to-drop
"
]]:
isOver
&&
!
allowToDrop
,
})
}
ref=
{
dropRef
}
>
<
div
className=
{
styles
[
"
card-continer
"
]
}
>
{
cards
.
map
((
card
,
i
)
=>
(
<
DeckCard
value=
{
card
}
key=
{
card
.
id
+
i
+
type
}
source=
{
type
}
onClick=
{
()
=>
{
onElementClick
(
card
);
}
}
onRightClick=
{
()
=>
{
onElementRightClick
?.(
card
);
}
}
/>
))
}
<
div
className=
{
styles
[
"
editing-zone-name
"
]
}
>
{
`${type.toUpperCase()}: ${cards.length}`
}
</
div
>
</
div
>
</
div
>
);
};
src/ui/Shared/index.ts
View file @
41c6c3c2
export
*
from
"
./Background
"
;
export
*
from
"
./Background
"
;
export
*
from
"
./CardEffectText
"
;
export
*
from
"
./CardEffectText
"
;
export
*
from
"
./css
"
;
export
*
from
"
./css
"
;
export
*
from
"
./DeckCard
"
;
export
*
from
"
./DeckZone
"
;
export
*
from
"
./IconFont
"
;
export
*
from
"
./IconFont
"
;
export
*
from
"
./Loading
"
;
export
*
from
"
./Loading
"
;
export
*
from
"
./Scrollbar
"
;
export
*
from
"
./Scrollbar
"
;
...
...
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