From afcd6abd0e8aa003ea662ea31ccfeeee71600470 Mon Sep 17 00:00:00 2001 From: myl7 Date: Sun, 28 Nov 2021 21:25:38 +0800 Subject: [PATCH] add folder download notification --- components/FileListing.tsx | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/components/FileListing.tsx b/components/FileListing.tsx index 66b5aa7..5910cc8 100644 --- a/components/FileListing.tsx +++ b/components/FileListing.tsx @@ -304,7 +304,6 @@ const FileListing: FunctionComponent<{ query?: ParsedUrlQuery }> = ({ query }) = // Folder recursive download const handleFolderDownload = (path: string, id: string, name?: string) => () => { - setFolderGenerating({ ...folderGenerating, [id]: true }) const files = (async function* () { for await (const { meta: c, path: p, isFolder } of treeList(path)) { yield { @@ -315,7 +314,17 @@ const FileListing: FunctionComponent<{ query?: ParsedUrlQuery }> = ({ query }) = } } })() - saveTreeFiles(files, name).then(() => setFolderGenerating({ ...folderGenerating, [id]: false })) + setFolderGenerating({ ...folderGenerating, [id]: true }) + const toastId = toast.loading('Downloading folder. This may be slow...') + saveTreeFiles(files, name).then(() => { + setFolderGenerating({ ...folderGenerating, [id]: false }) + toast.dismiss(toastId) + toast.success('Finished to download folder.') + }).catch(() => { + setFolderGenerating({ ...folderGenerating, [id]: false }) + toast.dismiss(toastId) + toast.error('Failed to download folder.') + }) } return (