Skip to content

armgit / memos

Public Imported from GitHub
0

Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.

chore: support uploads multi files (#191)

boojack422e190c9617
diff --git a/web/src/components/MemoEditor.tsx b/web/src/components/MemoEditor.tsx
index 8df8234a1..8149b9bb1 100644
--- a/web/src/components/MemoEditor.tsx
+++ b/web/src/components/MemoEditor.tsx
@@ -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 = false;
- inputEl.accept = "image/png, image/gif, image/jpeg";
+ inputEl.multiple = true;
+ 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(`![](${url})`);
+ for (const file of inputEl.files) {
+ const url = await handleUploadFile(file);
+ if (url) {
+ editorRef.current?.insertText(`![](${url})`);
+ }
}
};
inputEl.click();
+ document.body.removeChild(inputEl);
}, []);
const handleFullscreenBtnClick = () => {
diff --git a/web/src/components/ResourcesDialog.tsx b/web/src/components/ResourcesDialog.tsx
index f4f37388e..f9d823063 100644
--- a/web/src/components/ResourcesDialog.tsx
+++ b/web/src/components/ResourcesDialog.tsx
@@ -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 = false;
- inputEl.accept = "image/png, image/gif, image/jpeg";
+ inputEl.multiple = true;
+ 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
diff --git a/web/src/less/resources-dialog.less b/web/src/less/resources-dialog.less
index af86c3edd..90bf2bf73 100644
--- a/web/src/less/resources-dialog.less
+++ b/web/src/less/resources-dialog.less
@@ -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-80;
+ @apply px-3 py-1 rounded flex flex-row justify-center items-center border border-dashed border-blue-600 text-blue-600 bg-blue-50;
> .icon-img {
@apply w-4 h-auto mr-1;