From 1236c080f56cad15b6e8a46fb6953cb7d0cc3d56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=99=8D=EC=B0=BD=EA=B8=B0?= Date: Sun, 22 Sep 2024 04:15:01 +0900 Subject: [PATCH] =?UTF-8?q?Feat:=20=EC=97=85=EB=A1=9C=EB=93=9C=20=EC=99=84?= =?UTF-8?q?=EB=A3=8C=20=EB=98=90=EB=8A=94=20=EC=8B=A4=ED=8C=A8=20=EC=8B=9C?= =?UTF-8?q?=20=EB=8B=AB=EA=B8=B0=20=EB=B2=84=ED=8A=BC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/api/imageApi.ts | 5 +- .../ImageFolderUploadForm.tsx | 116 ++++++++++++------ .../ImageFolderUploadModal/index.tsx | 3 +- 3 files changed, 83 insertions(+), 41 deletions(-) diff --git a/frontend/src/api/imageApi.ts b/frontend/src/api/imageApi.ts index 3354d49..460b4de 100644 --- a/frontend/src/api/imageApi.ts +++ b/frontend/src/api/imageApi.ts @@ -60,5 +60,8 @@ export async function uploadImageFolder(memberId: number, projectId: number, fil params: { memberId }, } ) - .then(({ data }) => data); + .then(({ data }) => data) + .catch((error) => { + return Promise.reject(error); + }); } diff --git a/frontend/src/components/ImageFolderUploadModal/ImageFolderUploadForm.tsx b/frontend/src/components/ImageFolderUploadModal/ImageFolderUploadForm.tsx index 22f400d..ef355d7 100644 --- a/frontend/src/components/ImageFolderUploadModal/ImageFolderUploadForm.tsx +++ b/frontend/src/components/ImageFolderUploadModal/ImageFolderUploadForm.tsx @@ -4,13 +4,27 @@ import { cn } from '@/lib/utils'; import { uploadImageFolder } from '@/api/imageApi'; import useAuthStore from '@/stores/useAuthStore'; -export default function ImageFolderUploadForm({ projectId, parentId }: { projectId: number; parentId: number }) { +export default function ImageFolderUploadForm({ + onClose, + projectId, + parentId, +}: { + onClose: () => void; + projectId: number; + parentId: number; +}) { const profile = useAuthStore((state) => state.profile); const memberId = profile?.id || 0; const [files, setFiles] = useState([]); const [isDragging, setIsDragging] = useState(false); const [isUploading, setIsUploading] = useState(false); + const [progress, setProgress] = useState(0); + const [isFailed, setIsFailed] = useState(false); + + const handleClose = () => { + onClose(); + }; const handleChange = (event: React.ChangeEvent) => { const newFiles = event.target.files; @@ -34,55 +48,79 @@ export default function ImageFolderUploadForm({ projectId, parentId }: { project setIsDragging(false); }; - const handleClick = async () => { + const handleUpload = async () => { setIsUploading(true); - await uploadImageFolder(memberId, projectId, files, parentId); - setFiles([]); - setIsUploading(false); + setProgress(0); + + await uploadImageFolder(memberId, projectId, files, parentId) + .then(() => { + setProgress(100); + }) + .catch(() => { + setProgress(100); + setIsFailed(true); + }); }; return (
-
- - {isDragging ? ( -

드래그한 파일을 여기에 놓으세요

- ) : ( -

- 파일을 업로드하려면 여기를 클릭하거나 -
- 파일을 드래그하여 여기에 놓으세요 -

- )} -
+ {!isUploading && ( +
+ + {isDragging ? ( +

드래그한 폴더를 여기에 놓으세요

+ ) : ( +

+ 폴더를 업로드하려면 여기를 클릭하거나 +
+ 폴더를 드래그하여 여기에 놓으세요 +

+ )} +
+ )} {files.length > 0 && (
    {files.map((file, index) => ( -
  • {file.webkitRelativePath}
  • +
  • {file.webkitRelativePath || file.name}
  • ))}
)} - + {isUploading ? ( + + ) : ( + + )}
); } diff --git a/frontend/src/components/ImageFolderUploadModal/index.tsx b/frontend/src/components/ImageFolderUploadModal/index.tsx index 3cfd456..96f737c 100644 --- a/frontend/src/components/ImageFolderUploadModal/index.tsx +++ b/frontend/src/components/ImageFolderUploadModal/index.tsx @@ -7,7 +7,7 @@ export default function WorkSpaceCreateModal({ projectId, parentId = 0 }: { proj const [isOpen, setIsOpen] = React.useState(false); const handleOpen = () => setIsOpen(true); - // const handleClose = () => setIsOpen(false); + const handleClose = () => setIsOpen(false); return (