diff --git a/components/FileListing.tsx b/components/FileListing.tsx index 5719dff..66b5aa7 100644 --- a/components/FileListing.tsx +++ b/components/FileListing.tsx @@ -166,6 +166,7 @@ const FileListing: FunctionComponent<{ query?: ParsedUrlQuery }> = ({ query }) = const [selected, setSelected] = useState<{ [key: string]: boolean }>({}) const [totalSelected, setTotalSelected] = useState<0 | 1 | 2>(0) const [totalGenerating, setTotalGenerating] = useState(false) + const [folderGenerating, setFolderGenerating] = useState<{ [key: string]: boolean }>({}) const router = useRouter() const clipboard = useClipboard() @@ -302,7 +303,8 @@ const FileListing: FunctionComponent<{ query?: ParsedUrlQuery }> = ({ query }) = } // Folder recursive download - const handleFolderDownload = (path: string, name?: string) => () => { + 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 { @@ -313,7 +315,7 @@ const FileListing: FunctionComponent<{ query?: ParsedUrlQuery }> = ({ query }) = } } })() - saveTreeFiles(files, name) + saveTreeFiles(files, name).then(() => setFolderGenerating({ ...folderGenerating, [id]: false })) } return ( @@ -415,15 +417,20 @@ const FileListing: FunctionComponent<{ query?: ParsedUrlQuery }> = ({ query }) = > - { - handleFolderDownload(`${path === '/' ? '' : path}/${encodeURIComponent(c.name)}`, c.name)() - }} - > - - + {folderGenerating[c.id] ? ( + + ) : ( + { + const p = `${path === '/' ? '' : path}/${encodeURIComponent(c.name)}` + handleFolderDownload(p, c.id, c.name)() + }} + > + + + )} ) : (