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
422e190c
Unverified
Commit
422e190c
authored
Sep 02, 2022
by
boojack
Committed by
GitHub
Sep 02, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: support uploads multi files (#191)
parent
3e13fa1c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
21 deletions
+41
-21
MemoEditor.tsx
web/src/components/MemoEditor.tsx
+12
-6
ResourcesDialog.tsx
web/src/components/ResourcesDialog.tsx
+27
-13
resources-dialog.less
web/src/less/resources-dialog.less
+2
-2
No files found.
web/src/components/MemoEditor.tsx
View file @
422e190c
...
...
@@ -209,21 +209,27 @@ const MemoEditor: React.FC<Props> = () => {
const
handleUploadFileBtnClick
=
useCallback
(()
=>
{
const
inputEl
=
document
.
createElement
(
"input"
);
inputEl
.
style
.
position
=
"fixed"
;
inputEl
.
style
.
top
=
"-100vh"
;
inputEl
.
style
.
left
=
"-100vw"
;
document
.
body
.
appendChild
(
inputEl
);
inputEl
.
type
=
"file"
;
inputEl
.
multiple
=
fals
e
;
inputEl
.
accept
=
"image/
png, image/gif, image/jpeg
"
;
inputEl
.
multiple
=
tru
e
;
inputEl
.
accept
=
"image/
*
"
;
inputEl
.
onchange
=
async
()
=>
{
if
(
!
inputEl
.
files
||
inputEl
.
files
.
length
===
0
)
{
return
;
}
const
file
=
inputEl
.
files
[
0
];
const
url
=
await
handleUploadFile
(
file
);
if
(
url
)
{
editorRef
.
current
?.
insertText
(
``
);
for
(
const
file
of
inputEl
.
files
)
{
const
url
=
await
handleUploadFile
(
file
);
if
(
url
)
{
editorRef
.
current
?.
insertText
(
``
);
}
}
};
inputEl
.
click
();
document
.
body
.
removeChild
(
inputEl
);
},
[]);
const
handleFullscreenBtnClick
=
()
=>
{
...
...
web/src/components/ResourcesDialog.tsx
View file @
422e190c
...
...
@@ -6,6 +6,7 @@ import { resourceService } from "../services";
import
Dropdown
from
"./common/Dropdown"
;
import
{
generateDialog
}
from
"./Dialog"
;
import
{
showCommonDialog
}
from
"./Dialog/CommonDialog"
;
import
showPreviewImageDialog
from
"./PreviewImageDialog"
;
import
Icon
from
"./Icon"
;
import
toastHelper
from
"./Toast"
;
import
"../less/resources-dialog.less"
;
...
...
@@ -51,9 +52,13 @@ const ResourcesDialog: React.FC<Props> = (props: Props) => {
}
const
inputEl
=
document
.
createElement
(
"input"
);
inputEl
.
style
.
position
=
"fixed"
;
inputEl
.
style
.
top
=
"-100vh"
;
inputEl
.
style
.
left
=
"-100vw"
;
document
.
body
.
appendChild
(
inputEl
);
inputEl
.
type
=
"file"
;
inputEl
.
multiple
=
fals
e
;
inputEl
.
accept
=
"image/
png, image/gif, image/jpeg
"
;
inputEl
.
multiple
=
tru
e
;
inputEl
.
accept
=
"image/
*
"
;
inputEl
.
onchange
=
async
()
=>
{
if
(
!
inputEl
.
files
||
inputEl
.
files
.
length
===
0
)
{
return
;
...
...
@@ -64,21 +69,29 @@ const ResourcesDialog: React.FC<Props> = (props: Props) => {
isUploadingResource
:
true
,
});
const
file
=
inputEl
.
files
[
0
];
try
{
for
(
const
file
of
inputEl
.
files
)
{
await
resourceService
.
upload
(
file
);
}
catch
(
error
:
any
)
{
console
.
error
(
error
);
toastHelper
.
error
(
error
.
response
.
data
.
message
);
}
finally
{
setState
({
...
state
,
isUploadingResource
:
false
,
});
await
fetchResources
();
try
{
await
resourceService
.
upload
(
file
);
}
catch
(
error
:
any
)
{
console
.
error
(
error
);
toastHelper
.
error
(
error
.
response
.
data
.
message
);
}
finally
{
setState
({
...
state
,
isUploadingResource
:
false
,
});
}
}
await
fetchResources
();
};
inputEl
.
click
();
document
.
body
.
removeChild
(
inputEl
);
};
const
handlPreviewBtnClick
=
(
resource
:
Resource
)
=>
{
showPreviewImageDialog
(
`
${
window
.
location
.
origin
}
/h/r/
${
resource
.
id
}
/
${
resource
.
filename
}
`
);
};
const
handleCopyResourceLinkBtnClick
=
(
resource
:
Resource
)
=>
{
...
...
@@ -139,6 +152,7 @@ const ResourcesDialog: React.FC<Props> = (props: Props) => {
<
span
className=
"field-text"
>
{
resource
.
type
}
</
span
>
<
div
className=
"buttons-container"
>
<
Dropdown
className=
"actions-dropdown"
>
<
button
onClick=
{
()
=>
handlPreviewBtnClick
(
resource
)
}
>
Preview
</
button
>
<
button
onClick=
{
()
=>
handleCopyResourceLinkBtnClick
(
resource
)
}
>
Copy Link
</
button
>
<
button
className=
"delete-btn"
onClick=
{
()
=>
handleDeleteResourceBtnClick
(
resource
)
}
>
Delete
...
...
web/src/less/resources-dialog.less
View file @
422e190c
...
...
@@ -14,10 +14,10 @@
}
> .upload-resource-container {
@apply mt-2 mb-4
w-full rounded flex flex-row justify-start items-center
;
@apply mt-2 mb-4
py-8 cursor-pointer w-full rounded flex flex-row justify-center items-center bg-blue-50 border border-blue-600 hover:opacity-80
;
> .upload-resource-btn {
@apply px-3 py-1 rounded
cursor-pointer flex flex-row justify-center items-center border border-dashed border-blue-600 text-blue-600 bg-blue-50 hover:opacity-8
0;
@apply px-3 py-1 rounded
flex flex-row justify-center items-center border border-dashed border-blue-600 text-blue-600 bg-blue-5
0;
> .icon-img {
@apply w-4 h-auto mr-1;
...
...
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