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
df5d859d
Commit
df5d859d
authored
Aug 13, 2023
by
timel
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev/copy-deck-to-clipboard' into 'main'
feat: copy deck to clipboard See merge request
!258
parents
f0a2423d
f24a07ec
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
5 deletions
+40
-5
src/ui/BuildDeck/DeckSelect.tsx
src/ui/BuildDeck/DeckSelect.tsx
+15
-2
src/ui/BuildDeck/index.tsx
src/ui/BuildDeck/index.tsx
+6
-0
src/ui/BuildDeck/utils.ts
src/ui/BuildDeck/utils.ts
+19
-3
No files found.
src/ui/BuildDeck/DeckSelect.tsx
View file @
df5d859d
import
{
import
{
CopyOutlined
,
DeleteOutlined
,
DeleteOutlined
,
DownloadOutlined
,
DownloadOutlined
,
FileAddOutlined
,
FileAddOutlined
,
InboxOutlined
,
InboxOutlined
,
PlusOutlined
,
PlusOutlined
,
CopyOutlined
,
}
from
"
@ant-design/icons
"
;
}
from
"
@ant-design/icons
"
;
import
{
App
,
Button
,
Dropdown
,
MenuProps
,
Upload
,
UploadProps
}
from
"
antd
"
;
import
{
App
,
Button
,
Dropdown
,
MenuProps
,
Upload
,
UploadProps
}
from
"
antd
"
;
import
React
,
{
useRef
,
useState
}
from
"
react
"
;
import
React
,
{
useRef
,
useState
}
from
"
react
"
;
...
@@ -20,7 +20,8 @@ export const DeckSelect: React.FC<{
...
@@ -20,7 +20,8 @@ export const DeckSelect: React.FC<{
onSelect
:
(
deckName
:
string
)
=>
any
;
onSelect
:
(
deckName
:
string
)
=>
any
;
onDelete
:
(
deckName
:
string
)
=>
Promise
<
any
>
;
onDelete
:
(
deckName
:
string
)
=>
Promise
<
any
>
;
onDownload
:
(
deckName
:
string
)
=>
any
;
onDownload
:
(
deckName
:
string
)
=>
any
;
}
>
=
({
decks
,
selected
,
onSelect
,
onDelete
,
onDownload
})
=>
{
onCopy
:
(
deckName
:
string
)
=>
Promise
<
any
>
;
}
>
=
({
decks
,
selected
,
onSelect
,
onDelete
,
onDownload
,
onCopy
})
=>
{
const
newDeck
=
useRef
<
IDeck
[]
>
([]);
const
newDeck
=
useRef
<
IDeck
[]
>
([]);
const
{
modal
,
message
}
=
App
.
useApp
();
const
{
modal
,
message
}
=
App
.
useApp
();
...
@@ -130,6 +131,17 @@ export const DeckSelect: React.FC<{
...
@@ -130,6 +131,17 @@ export const DeckSelect: React.FC<{
{
selected
===
deckName
&&
<
div
className=
{
styles
.
selected
}
/>
}
{
selected
===
deckName
&&
<
div
className=
{
styles
.
selected
}
/>
}
<
span
>
{
deckName
}
</
span
>
<
span
>
{
deckName
}
</
span
>
<
div
className=
{
styles
.
btns
}
>
<
div
className=
{
styles
.
btns
}
>
<
Button
icon=
{
<
CopyOutlined
/>
}
type=
"text"
size=
"small"
onClick=
{
cancelBubble
(
async
()
=>
{
const
result
=
await
onCopy
(
deckName
);
result
?
message
.
success
(
"
复制成功
"
)
:
message
.
error
(
"
复制失败
"
);
})
}
/>
<
Button
<
Button
icon=
{
<
DeleteOutlined
/>
}
icon=
{
<
DeleteOutlined
/>
}
type=
"text"
type=
"text"
...
@@ -139,6 +151,7 @@ export const DeckSelect: React.FC<{
...
@@ -139,6 +151,7 @@ export const DeckSelect: React.FC<{
onSelect
(
decks
[
0
].
deckName
);
onSelect
(
decks
[
0
].
deckName
);
})
}
})
}
/>
/>
<
Button
<
Button
icon=
{
<
DownloadOutlined
/>
}
icon=
{
<
DownloadOutlined
/>
}
type=
"text"
type=
"text"
...
...
src/ui/BuildDeck/index.tsx
View file @
df5d859d
...
@@ -44,6 +44,7 @@ import { Filter } from "./Filter";
...
@@ -44,6 +44,7 @@ import { Filter } from "./Filter";
import
styles
from
"
./index.module.scss
"
;
import
styles
from
"
./index.module.scss
"
;
import
{
editDeckStore
}
from
"
./store
"
;
import
{
editDeckStore
}
from
"
./store
"
;
import
{
import
{
copyDeckToClipboard
,
downloadDeckAsYDK
,
downloadDeckAsYDK
,
editingDeckToIDeck
,
editingDeckToIDeck
,
iDeckToEditingDeck
,
iDeckToEditingDeck
,
...
@@ -106,6 +107,11 @@ export const Component: React.FC = () => {
...
@@ -106,6 +107,11 @@ export const Component: React.FC = () => {
const
deck
=
deckStore
.
get
(
name
);
const
deck
=
deckStore
.
get
(
name
);
if
(
deck
)
downloadDeckAsYDK
(
deck
);
if
(
deck
)
downloadDeckAsYDK
(
deck
);
}
}
}
}
onCopy=
{
async
(
name
)
=>
{
const
deck
=
deckStore
.
get
(
name
);
if
(
deck
)
return
await
copyDeckToClipboard
(
deck
);
else
return
false
;
}
}
/>
/>
</
ScrollableArea
>
</
ScrollableArea
>
<
HigherCardDetail
/>
<
HigherCardDetail
/>
...
...
src/ui/BuildDeck/utils.ts
View file @
df5d859d
...
@@ -36,8 +36,8 @@ export const compareCards = (a: CardMeta, b: CardMeta): number => {
...
@@ -36,8 +36,8 @@ export const compareCards = (a: CardMeta, b: CardMeta): number => {
return
a
.
id
-
b
.
id
;
return
a
.
id
-
b
.
id
;
};
};
/**
下载卡组YDK文件 *
*/
/**
生成ydk格式的卡组文本
*/
export
function
downloadDeckAsYDK
(
deck
:
IDeck
)
{
function
genYdkText
(
deck
:
IDeck
):
string
{
const
lines
:
string
[]
=
[];
const
lines
:
string
[]
=
[];
lines
.
push
(
"
#created by neos
"
);
lines
.
push
(
"
#created by neos
"
);
lines
.
push
(
"
#main
"
);
lines
.
push
(
"
#main
"
);
...
@@ -46,7 +46,12 @@ export function downloadDeckAsYDK(deck: IDeck) {
...
@@ -46,7 +46,12 @@ export function downloadDeckAsYDK(deck: IDeck) {
lines
.
push
(...
deck
.
extra
.
map
((
cardId
)
=>
cardId
.
toString
()));
lines
.
push
(...
deck
.
extra
.
map
((
cardId
)
=>
cardId
.
toString
()));
lines
.
push
(
"
!side
"
);
lines
.
push
(
"
!side
"
);
lines
.
push
(...
deck
.
side
.
map
((
cardId
)
=>
cardId
.
toString
()));
lines
.
push
(...
deck
.
side
.
map
((
cardId
)
=>
cardId
.
toString
()));
const
text
=
lines
.
join
(
"
\n
"
);
return
lines
.
join
(
"
\n
"
);
}
/** 下载卡组YDK文件 **/
export
function
downloadDeckAsYDK
(
deck
:
IDeck
)
{
const
text
=
genYdkText
(
deck
);
const
blob
=
new
Blob
([
text
],
{
type
:
"
text/plain
"
});
const
blob
=
new
Blob
([
text
],
{
type
:
"
text/plain
"
});
const
url
=
URL
.
createObjectURL
(
blob
);
const
url
=
URL
.
createObjectURL
(
blob
);
...
@@ -58,3 +63,14 @@ export function downloadDeckAsYDK(deck: IDeck) {
...
@@ -58,3 +63,14 @@ export function downloadDeckAsYDK(deck: IDeck) {
URL
.
revokeObjectURL
(
url
);
URL
.
revokeObjectURL
(
url
);
}
}
/** 将卡组复制到剪贴板 */
export
async
function
copyDeckToClipboard
(
deck
:
IDeck
):
Promise
<
boolean
>
{
const
text
=
genYdkText
(
deck
);
try
{
await
navigator
.
clipboard
.
writeText
(
text
);
return
true
;
}
catch
(
e
)
{
return
false
;
}
}
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