From 15ee2316feea97b643050887c636af7698b8df57 Mon Sep 17 00:00:00 2001 From: Wallys Ferreira Date: Thu, 25 Jan 2024 23:55:52 +0000 Subject: [PATCH 1/9] feat: add property 'multiple' to file input --- ui/src/components/docs-input.tsx | 1 + ui/src/components/image-input.tsx | 1 + 2 files changed, 2 insertions(+) diff --git a/ui/src/components/docs-input.tsx b/ui/src/components/docs-input.tsx index 2d5893d..b9e7f3f 100644 --- a/ui/src/components/docs-input.tsx +++ b/ui/src/components/docs-input.tsx @@ -32,6 +32,7 @@ const DocsInput: React.FC<{ onChange={getFileName} type="file" accept="text/plain, application/msword, application/vnd.openxmlformats-officedocument.wordprocessingml.document, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.openxmlformats-officedocument.presentationml.presentation, application/pdf, application/rtf, application/x-freearc" + multiple name="document" id="document" aria-label="Select document" diff --git a/ui/src/components/image-input.tsx b/ui/src/components/image-input.tsx index b20890e..fc0220d 100644 --- a/ui/src/components/image-input.tsx +++ b/ui/src/components/image-input.tsx @@ -32,6 +32,7 @@ const ImageInput: React.FC<{ onChange={getFileName} type="file" accept="image/jpeg, image/png, image/jpg, image/webp, image/gif, image/bmp" + multiple name="image" id="image" aria-label="Select image" From 215bc4319320019a27447e777cff33b6557e0be8 Mon Sep 17 00:00:00 2001 From: Wallys Ferreira Date: Fri, 26 Jan 2024 00:22:00 +0000 Subject: [PATCH 2/9] feat: sends multiple documents or images to api --- ui/src/components/upload.tsx | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/ui/src/components/upload.tsx b/ui/src/components/upload.tsx index b259cc8..bf27fc5 100644 --- a/ui/src/components/upload.tsx +++ b/ui/src/components/upload.tsx @@ -28,24 +28,25 @@ const Upload = () => { if (files !== null && files !== undefined) { toast.loading("Uploading..."); - const toUpload = files[0]; - const form = new FormData(); const type = tab === "docs" ? "doc" : "image"; - form.append(type, toUpload); - axios - .post<{ url: string }>(`/api/cdn/upload/${type}`, form) - .then((res) => { - if (res.status === 200) { + + for (let file of files) { + const form = new FormData(); + form.append(type, file); + axios + .post<{ url: string }>(`/api/cdn/upload/${type}`, form) + .then((res) => { + if (res.status === 200) { + toast.dismiss(); + toast.success("Successfully uploaded file!"); + getSize(setSize, setLoading); + } + }) + .catch((err: Error) => { toast.dismiss(); - toast.success("Successfully uploaded file!"); - getSize(setSize, setLoading); - location.reload(); - } - }) - .catch((err: Error) => { - toast.dismiss(); - toast.error(err.message); - }); + toast.error(err.message); + }); + } } }; From 56c05d3d73f79d0a05c2b6c2de4691f035b695c6 Mon Sep 17 00:00:00 2001 From: Wallys Ferreira Date: Fri, 26 Jan 2024 02:00:26 +0000 Subject: [PATCH 3/9] fix: show icon for each file being uploaded --- ui/src/components/docs-input.tsx | 28 +++++++++++++++++++--------- ui/src/components/image-input.tsx | 29 ++++++++++++++++++++--------- 2 files changed, 39 insertions(+), 18 deletions(-) diff --git a/ui/src/components/docs-input.tsx b/ui/src/components/docs-input.tsx index b9e7f3f..c850a67 100644 --- a/ui/src/components/docs-input.tsx +++ b/ui/src/components/docs-input.tsx @@ -4,22 +4,32 @@ import { FileText } from "lucide-react"; const DocsInput: React.FC<{ fileRef: React.RefObject; }> = ({ fileRef }) => { - const [fileName, setFileName] = useState(undefined); + const [fileNames, setFileNames] = useState([]); - const getFileName = () => { + const getFileNames = () => { if (fileRef.current?.files != null) { - setFileName(fileRef.current.files[0].name); + let names = [] + + for (let file of fileRef.current.files) { + names.push(file.name) + } + + setFileNames(names) } }; return (
- {fileName ? ( -
- - {fileName} -
+ {fileNames.length > 0 ? ( +
+ {fileNames.map(fileName => ( +
+ + {fileName} +
+ ))} +
) : (
@@ -29,7 +39,7 @@ const DocsInput: React.FC<{