feat(Upload/Popup): close the popup automatically when the upload is successful

This commit is contained in:
Aminejv 2021-10-12 13:54:52 +01:00
parent 3216e863c9
commit 3ddafb40ec
2 changed files with 11 additions and 1 deletions

View File

@ -94,6 +94,7 @@ const useUploadPopup = ({ totalFilesSummary }) => {
const totalFilesSummaryRef = React.useRef(); const totalFilesSummaryRef = React.useRef();
totalFilesSummaryRef.current = totalFilesSummary; totalFilesSummaryRef.current = totalFilesSummary;
React.useEffect(() => { React.useEffect(() => {
clearTimeout(timeoutRef.current);
if (!isFinished) return; if (!isFinished) return;
//NOTE(amine): if all the upload items have been canceled, hide the upload popup //NOTE(amine): if all the upload items have been canceled, hide the upload popup
if (totalFilesSummaryRef.current.total === 0) { if (totalFilesSummaryRef.current.total === 0) {
@ -101,8 +102,16 @@ const useUploadPopup = ({ totalFilesSummary }) => {
resetUploadState(); resetUploadState();
return; return;
} }
clearTimeout(timeoutRef.current);
expandUploadSummary(); expandUploadSummary();
//NOTE(amine): if the upload is successful, automatically close the popup
if (totalFilesSummaryRef.current.failed === 0) {
timeoutRef.current = setTimeout(() => {
hideUploadPopup();
resetUploadState();
}, 10000);
}
}, [isFinished]); }, [isFinished]);
/** /**

View File

@ -83,6 +83,7 @@ const useUpload = () => {
blob: file, blob: file,
}, },
}, },
isFinished: false,
totalFiles: prev.totalFiles + 1, totalFiles: prev.totalFiles + 1,
totalBytes: prev.totalBytes + file.size, totalBytes: prev.totalBytes + file.size,
})); }));