Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
ff447ad2
Unverified
Commit
ff447ad2
authored
May 03, 2023
by
Stephen Zhou
Committed by
GitHub
May 03, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: support file sorting when uploading (#1627)
parent
c081030d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
4 deletions
+64
-4
CreateResourceDialog.tsx
web/src/components/CreateResourceDialog.tsx
+55
-3
ResourcesDashboard.tsx
web/src/pages/ResourcesDashboard.tsx
+9
-1
No files found.
web/src/components/CreateResourceDialog.tsx
View file @
ff447ad2
...
@@ -36,6 +36,33 @@ const CreateResourceDialog: React.FC<Props> = (props: Props) => {
...
@@ -36,6 +36,33 @@ const CreateResourceDialog: React.FC<Props> = (props: Props) => {
const
[
fileList
,
setFileList
]
=
useState
<
File
[]
>
([]);
const
[
fileList
,
setFileList
]
=
useState
<
File
[]
>
([]);
const
fileInputRef
=
useRef
<
HTMLInputElement
>
(
null
);
const
fileInputRef
=
useRef
<
HTMLInputElement
>
(
null
);
const
handleReorderFileList
=
(
fileName
:
string
,
direction
:
"up"
|
"down"
)
=>
{
const
fileIndex
=
fileList
.
findIndex
((
file
)
=>
file
.
name
===
fileName
);
if
(
fileIndex
===
-
1
)
{
return
;
}
const
newFileList
=
[...
fileList
];
if
(
direction
===
"up"
)
{
if
(
fileIndex
===
0
)
{
return
;
}
const
temp
=
newFileList
[
fileIndex
-
1
];
newFileList
[
fileIndex
-
1
]
=
newFileList
[
fileIndex
];
newFileList
[
fileIndex
]
=
temp
;
}
else
if
(
direction
===
"down"
)
{
if
(
fileIndex
===
fileList
.
length
-
1
)
{
return
;
}
const
temp
=
newFileList
[
fileIndex
+
1
];
newFileList
[
fileIndex
+
1
]
=
newFileList
[
fileIndex
];
newFileList
[
fileIndex
]
=
temp
;
}
setFileList
(
newFileList
);
};
const
handleCloseDialog
=
()
=>
{
const
handleCloseDialog
=
()
=>
{
if
(
onCancel
)
{
if
(
onCancel
)
{
onCancel
();
onCancel
();
...
@@ -124,7 +151,12 @@ const CreateResourceDialog: React.FC<Props> = (props: Props) => {
...
@@ -124,7 +151,12 @@ const CreateResourceDialog: React.FC<Props> = (props: Props) => {
if
(
!
fileInputRef
.
current
||
!
fileInputRef
.
current
.
files
)
{
if
(
!
fileInputRef
.
current
||
!
fileInputRef
.
current
.
files
)
{
return
;
return
;
}
}
for
(
const
file
of
fileInputRef
.
current
.
files
)
{
const
filesOnInput
=
Array
.
from
(
fileInputRef
.
current
.
files
);
for
(
const
file
of
fileList
)
{
const
fileOnInput
=
filesOnInput
.
find
((
fileOnInput
)
=>
fileOnInput
.
name
===
file
.
name
);
if
(
!
fileOnInput
)
{
continue
;
}
const
resource
=
await
resourceStore
.
createResourceWithBlob
(
file
);
const
resource
=
await
resourceStore
.
createResourceWithBlob
(
file
);
createdResourceList
.
push
(
resource
);
createdResourceList
.
push
(
resource
);
}
}
...
@@ -182,10 +214,30 @@ const CreateResourceDialog: React.FC<Props> = (props: Props) => {
...
@@ -182,10 +214,30 @@ const CreateResourceDialog: React.FC<Props> = (props: Props) => {
/>
/>
</
div
>
</
div
>
<
List
size=
"sm"
sx=
{
{
width
:
"100%"
}
}
>
<
List
size=
"sm"
sx=
{
{
width
:
"100%"
}
}
>
{
fileList
.
map
((
file
)
=>
(
{
fileList
.
map
((
file
,
index
)
=>
(
<
Tooltip
title=
{
file
.
name
}
key=
{
file
.
name
}
placement=
"top"
>
<
Tooltip
title=
{
file
.
name
}
key=
{
file
.
name
}
placement=
"top"
>
<
ListItem
>
<
ListItem
className=
"flex justify-between"
>
<
Typography
noWrap
>
{
file
.
name
}
</
Typography
>
<
Typography
noWrap
>
{
file
.
name
}
</
Typography
>
<
div
className=
"flex gap-1"
>
<
button
onClick=
{
()
=>
{
handleReorderFileList
(
file
.
name
,
"up"
);
}
}
disabled=
{
index
===
0
}
className=
"disabled:opacity-50"
>
<
Icon
.
ArrowUp
className=
"w-4 h-4"
/>
</
button
>
<
button
onClick=
{
()
=>
{
handleReorderFileList
(
file
.
name
,
"down"
);
}
}
disabled=
{
index
===
fileList
.
length
-
1
}
className=
"disabled:opacity-50"
>
<
Icon
.
ArrowDown
className=
"w-4 h-4"
/>
</
button
>
</
div
>
</
ListItem
>
</
ListItem
>
</
Tooltip
>
</
Tooltip
>
))
}
))
}
...
...
web/src/pages/ResourcesDashboard.tsx
View file @
ff447ad2
...
@@ -224,7 +224,15 @@ const ResourcesDashboard = () => {
...
@@ -224,7 +224,15 @@ const ResourcesDashboard = () => {
<
Icon
.
Trash2
className=
"w-4 h-auto"
/>
<
Icon
.
Trash2
className=
"w-4 h-auto"
/>
</
Button
>
</
Button
>
)
}
)
}
<
Button
onClick=
{
()
=>
showCreateResourceDialog
({})
}
>
<
Button
onClick=
{
()
=>
showCreateResourceDialog
({
onConfirm
:
()
=>
{
resourceStore
.
fetchResourceList
();
},
})
}
>
<
Icon
.
Plus
className=
"w-4 h-auto"
/>
<
Icon
.
Plus
className=
"w-4 h-auto"
/>
</
Button
>
</
Button
>
<
Dropdown
<
Dropdown
...
...
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