From 1259922847170fe7deb480e117d90e0bf0b31b0a Mon Sep 17 00:00:00 2001 From: Elias Schneider Date: Fri, 14 Oct 2022 15:10:24 +0200 Subject: [PATCH] fix: improve failed upload error handling --- .../upload/UploadProgressIndicator.tsx | 5 ++--- frontend/src/pages/upload.tsx | 22 +++++++++++++++---- frontend/src/services/share.service.ts | 2 +- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/frontend/src/components/upload/UploadProgressIndicator.tsx b/frontend/src/components/upload/UploadProgressIndicator.tsx index fa96cb9b..11b9f0c3 100644 --- a/frontend/src/components/upload/UploadProgressIndicator.tsx +++ b/frontend/src/components/upload/UploadProgressIndicator.tsx @@ -1,6 +1,5 @@ import { RingProgress } from "@mantine/core"; -import { TbCircleCheck, TbCircleX } from "react-icons/tb";; - +import { TbCircleCheck, TbCircleX } from "react-icons/tb"; const UploadProgressIndicator = ({ progress }: { progress: number }) => { if (progress > 0 && progress < 100) { return ( @@ -10,7 +9,7 @@ const UploadProgressIndicator = ({ progress }: { progress: number }) => { size={25} /> ); - } else if (progress == 100) { + } else if (progress >= 100) { return ; } else { return ; diff --git a/frontend/src/pages/upload.tsx b/frontend/src/pages/upload.tsx index 825f0174..fdec6579 100644 --- a/frontend/src/pages/upload.tsx +++ b/frontend/src/pages/upload.tsx @@ -56,11 +56,25 @@ const Upload = () => { files[i].uploadingProgress = -1; } - if (!files.some((f) => f.uploadingProgress != 100)) { - await shareService.completeShare(share.id); + if ( + files.every( + (file) => + file.uploadingProgress >= 100 || file.uploadingProgress == -1 + ) + ) { + const fileErrorCount = files.filter( + (file) => file.uploadingProgress == -1 + ).length; setisUploading(false); - showCompletedUploadModal(modals, share); - setFiles([]); + if (fileErrorCount > 0) { + toast.error( + `${fileErrorCount} file(s) failed to upload. Try again.` + ); + } else { + await shareService.completeShare(share.id); + showCompletedUploadModal(modals, share); + setFiles([]); + } } } } catch (e) { diff --git a/frontend/src/services/share.service.ts b/frontend/src/services/share.service.ts index 2913803e..5a4f51f8 100644 --- a/frontend/src/services/share.service.ts +++ b/frontend/src/services/share.service.ts @@ -72,7 +72,7 @@ const uploadFile = async ( file: File, progressCallBack: (uploadingProgress: number) => void ) => { - var formData = new FormData(); + let formData = new FormData(); formData.append("file", file); return (