diff --git a/components/FileListing.tsx b/components/FileListing.tsx index f168ae0..839602a 100644 --- a/components/FileListing.tsx +++ b/components/FileListing.tsx @@ -136,6 +136,7 @@ const FileListing: FunctionComponent<{ query?: ParsedUrlQuery }> = ({ query }) = const [activeImageIdx, setActiveImageIdx] = useState(0) const [selected, setSelected] = useState<{[key: string]: boolean}>({}) const [totalSelected, setTotalSelected] = useState<0|1|2>(0) + const [totalGenerating, setTotalGenerating] = useState(false) const router = useRouter() const clipboard = useClipboard() @@ -237,13 +238,14 @@ const FileListing: FunctionComponent<{ query?: ParsedUrlQuery }> = ({ query }) = // Selected file download const handleDownloadSelected = () => { + setTotalGenerating(true) const folderName = path.substr(path.lastIndexOf('/') + 1) const folder = folderName ? folderName : undefined const files = children .filter((c :any) => !c.folder) .filter((c: any) => selected[c.id]) .map((c: any) => ({ name: c.name, url: c['@microsoft.graph.downloadUrl'] })) - saveFiles(files, folder) + saveFiles(files, folder, () => setTotalGenerating(false)) } return ( @@ -261,7 +263,29 @@ const FileListing: FunctionComponent<{ query?: ParsedUrlQuery }> = ({ query }) = indeterminate={true} title={"Select files"} /> - {totalSelected ? ( + {totalGenerating ? ( + + + + + + + ) : (totalSelected ? ( = ({ query }) = > - ) : ''} + ) : '')} diff --git a/utils/tools.ts b/utils/tools.ts index c9dd3e1..3ad0986 100644 --- a/utils/tools.ts +++ b/utils/tools.ts @@ -129,8 +129,9 @@ export const matchProtectedRoute = (route: string) => { * Download multiple files after compressing them into a zip * @param files Files to be downloaded * @param folder Optional folder name to hold files, otherwise flatten files in the zip + * @param onFinish Optional hook triggered after sending generated zip to browser to download */ -export const saveFiles = (files: { name: string, url: string }[], folder?: string) => { +export const saveFiles = (files: { name: string, url: string }[], folder?: string, onFinish?: () => void) => { const zip = new JSZip() const dir = folder ? zip.folder(folder)! : zip files.forEach(({ name, url }) => { @@ -146,5 +147,8 @@ export const saveFiles = (files: { name: string, url: string }[], folder?: strin el.click() window.URL.revokeObjectURL(bUrl) el.remove() + if (onFinish) { + onFinish() + } }) }