1
0
mirror of https://github.com/stonith404/pingvin-share.git synced 2024-07-04 08:20:13 +02:00

fix: improve failed upload error handling

This commit is contained in:
Elias Schneider 2022-10-14 15:10:24 +02:00
parent 58efc48ffa
commit 1259922847
3 changed files with 21 additions and 8 deletions

View File

@ -1,6 +1,5 @@
import { RingProgress } from "@mantine/core"; import { RingProgress } from "@mantine/core";
import { TbCircleCheck, TbCircleX } from "react-icons/tb";; import { TbCircleCheck, TbCircleX } from "react-icons/tb";
const UploadProgressIndicator = ({ progress }: { progress: number }) => { const UploadProgressIndicator = ({ progress }: { progress: number }) => {
if (progress > 0 && progress < 100) { if (progress > 0 && progress < 100) {
return ( return (
@ -10,7 +9,7 @@ const UploadProgressIndicator = ({ progress }: { progress: number }) => {
size={25} size={25}
/> />
); );
} else if (progress == 100) { } else if (progress >= 100) {
return <TbCircleCheck color="green" size={22} />; return <TbCircleCheck color="green" size={22} />;
} else { } else {
return <TbCircleX color="red" size={22} />; return <TbCircleX color="red" size={22} />;

View File

@ -56,11 +56,25 @@ const Upload = () => {
files[i].uploadingProgress = -1; files[i].uploadingProgress = -1;
} }
if (!files.some((f) => f.uploadingProgress != 100)) { if (
await shareService.completeShare(share.id); files.every(
(file) =>
file.uploadingProgress >= 100 || file.uploadingProgress == -1
)
) {
const fileErrorCount = files.filter(
(file) => file.uploadingProgress == -1
).length;
setisUploading(false); setisUploading(false);
showCompletedUploadModal(modals, share); if (fileErrorCount > 0) {
setFiles([]); toast.error(
`${fileErrorCount} file(s) failed to upload. Try again.`
);
} else {
await shareService.completeShare(share.id);
showCompletedUploadModal(modals, share);
setFiles([]);
}
} }
} }
} catch (e) { } catch (e) {

View File

@ -72,7 +72,7 @@ const uploadFile = async (
file: File, file: File,
progressCallBack: (uploadingProgress: number) => void progressCallBack: (uploadingProgress: number) => void
) => { ) => {
var formData = new FormData(); let formData = new FormData();
formData.append("file", file); formData.append("file", file);
return ( return (