From c945f0029df164b3ffb2eeecce75184aafecdcb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=99=8D=EC=B0=BD=EA=B8=B0?= Date: Mon, 30 Sep 2024 03:56:53 +0900 Subject: [PATCH] =?UTF-8?q?Feat:=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EC=97=85?= =?UTF-8?q?=EB=A1=9C=EB=93=9C=20=EC=8B=9C=20=EC=A7=84=ED=96=89=EB=8F=84=20?= =?UTF-8?q?=ED=91=9C=EC=8B=9C=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 | 46 +++++++++++++++++-- .../ImageUploadFileForm.tsx | 16 ++++--- .../ImageUploadFolderForm.tsx | 17 ++++++- .../ImageUploadFolderModal/index.tsx | 3 +- .../ImageUploadZipForm.tsx | 17 ++++++- .../components/ImageUploadZipModal/index.tsx | 3 +- .../WorkspaceDropdownMenu/index.tsx | 2 + .../projects/useUploadImageFileQuery.ts | 4 +- .../projects/useUploadImageFolderQuery.ts | 15 +++++- .../projects/useUploadImageZipQuery.ts | 15 +++++- 10 files changed, 116 insertions(+), 22 deletions(-) diff --git a/frontend/src/api/imageApi.ts b/frontend/src/api/imageApi.ts index aaa0aec..f3a21cc 100644 --- a/frontend/src/api/imageApi.ts +++ b/frontend/src/api/imageApi.ts @@ -31,7 +31,13 @@ export async function changeImageStatus( .then(({ data }) => data); } -export async function uploadImageFile(memberId: number, projectId: number, folderId: number, files: File[]) { +export async function uploadImageFile( + memberId: number, + projectId: number, + folderId: number, + files: File[], + processCallback: (progress: number) => void +) { const formData = new FormData(); files.forEach((file) => { formData.append('imageList', file); @@ -40,30 +46,60 @@ export async function uploadImageFile(memberId: number, projectId: number, folde return api .post(`/projects/${projectId}/folders/${folderId}/images/file`, formData, { params: { memberId }, + onUploadProgress: (progressEvent) => { + if (progressEvent.total) { + const progress = Math.round((progressEvent.loaded * 100) / progressEvent.total); + processCallback(progress); + } + }, }) .then(({ data }) => data); } -export async function uploadImageFolder(memberId: number, projectId: number, files: File[]) { +export async function uploadImageFolder( + memberId: number, + projectId: number, + folderId: number, + files: File[], + processCallback: (progress: number) => void +) { const formData = new FormData(); files.forEach((file) => { formData.append('imageList', file); }); return api - .post(`/projects/${projectId}/folders/${0}/images/file`, formData, { + .post(`/projects/${projectId}/folders/${folderId}/images/file`, formData, { params: { memberId }, + onUploadProgress: (progressEvent) => { + if (progressEvent.total) { + const progress = Math.round((progressEvent.loaded * 100) / progressEvent.total); + processCallback(progress); + } + }, }) .then(({ data }) => data); } -export async function uploadImageZip(memberId: number, projectId: number, file: File) { +export async function uploadImageZip( + memberId: number, + projectId: number, + folderId: number, + file: File, + processCallback: (progress: number) => void +) { const formData = new FormData(); formData.append('folderZip', file); return api - .post(`/projects/${projectId}/folders/${0}/images/zip`, formData, { + .post(`/projects/${projectId}/folders/${folderId}/images/zip`, formData, { params: { memberId }, + onUploadProgress: (progressEvent) => { + if (progressEvent.total) { + const progress = Math.round((progressEvent.loaded * 100) / progressEvent.total); + processCallback(progress); + } + }, }) .then(({ data }) => data); } diff --git a/frontend/src/components/ImageUploadFileModal/ImageUploadFileForm.tsx b/frontend/src/components/ImageUploadFileModal/ImageUploadFileForm.tsx index dd64af4..71c5569 100644 --- a/frontend/src/components/ImageUploadFileModal/ImageUploadFileForm.tsx +++ b/frontend/src/components/ImageUploadFileModal/ImageUploadFileForm.tsx @@ -22,6 +22,7 @@ export default function ImageUploadFileForm({ const [isUploading, setIsUploading] = useState(false); const [isUploaded, setIsUploaded] = useState(false); const [isFailed, setIsFailed] = useState(false); + const [progress, setProgress] = useState(0); const uploadImageFile = useUploadImageFileQuery(); @@ -71,6 +72,9 @@ export default function ImageUploadFileForm({ projectId, folderId, files, + progressCallback: (progress: number) => { + setProgress(progress); + }, }, { onSuccess: () => { @@ -115,11 +119,11 @@ export default function ImageUploadFileForm({ )} {files.length > 0 && ( -
    +
      {files.map((file, index) => (
    • {file.webkitRelativePath || file.name} {isUploading ? ( @@ -127,19 +131,19 @@ export default function ImageUploadFileForm({ {isUploaded ? ( ) : isFailed ? ( ) : ( )} @@ -171,7 +175,7 @@ export default function ImageUploadFileForm({ } disabled={!isUploaded && !isFailed} > - {isFailed ? '업로드 실패 (닫기)' : isUploaded ? '업로드 완료 (닫기)' : '업로드 중...'} + {isFailed ? '업로드 실패 (닫기)' : isUploaded ? '업로드 완료 (닫기)' : `업로드 중... ${progress}%`} ) : ( ) : ( ) : (