From 3ddafb40ec11668ab0a73b107abeb574d22c718c Mon Sep 17 00:00:00 2001 From: Aminejv Date: Tue, 12 Oct 2021 13:54:52 +0100 Subject: [PATCH] feat(Upload/Popup): close the popup automatically when the upload is successful --- components/core/Upload/Popup.js | 11 ++++++++++- components/core/Upload/Provider.js | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/components/core/Upload/Popup.js b/components/core/Upload/Popup.js index f0fbd015..2614e01c 100644 --- a/components/core/Upload/Popup.js +++ b/components/core/Upload/Popup.js @@ -94,6 +94,7 @@ const useUploadPopup = ({ totalFilesSummary }) => { const totalFilesSummaryRef = React.useRef(); totalFilesSummaryRef.current = totalFilesSummary; React.useEffect(() => { + clearTimeout(timeoutRef.current); if (!isFinished) return; //NOTE(amine): if all the upload items have been canceled, hide the upload popup if (totalFilesSummaryRef.current.total === 0) { @@ -101,8 +102,16 @@ const useUploadPopup = ({ totalFilesSummary }) => { resetUploadState(); return; } - clearTimeout(timeoutRef.current); + expandUploadSummary(); + + //NOTE(amine): if the upload is successful, automatically close the popup + if (totalFilesSummaryRef.current.failed === 0) { + timeoutRef.current = setTimeout(() => { + hideUploadPopup(); + resetUploadState(); + }, 10000); + } }, [isFinished]); /** diff --git a/components/core/Upload/Provider.js b/components/core/Upload/Provider.js index f0d294bf..322b8912 100644 --- a/components/core/Upload/Provider.js +++ b/components/core/Upload/Provider.js @@ -83,6 +83,7 @@ const useUpload = () => { blob: file, }, }, + isFinished: false, totalFiles: prev.totalFiles + 1, totalBytes: prev.totalBytes + file.size, }));