add folder download notification

This commit is contained in:
myl7
2021-12-16 21:28:37 +08:00
parent 5a8bb2acda
commit afcd6abd0e
+11 -2
View File
@@ -304,7 +304,6 @@ const FileListing: FunctionComponent<{ query?: ParsedUrlQuery }> = ({ query }) =
// Folder recursive download // Folder recursive download
const handleFolderDownload = (path: string, id: string, name?: string) => () => { const handleFolderDownload = (path: string, id: string, name?: string) => () => {
setFolderGenerating({ ...folderGenerating, [id]: true })
const files = (async function* () { const files = (async function* () {
for await (const { meta: c, path: p, isFolder } of treeList(path)) { for await (const { meta: c, path: p, isFolder } of treeList(path)) {
yield { 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 ( return (