turn DownloadingToast into component to fix hook use in it

This commit is contained in:
myl7
2022-02-09 23:18:40 +08:00
parent fab8336d99
commit b68396bef8
2 changed files with 9 additions and 9 deletions
+2 -2
View File
@@ -239,7 +239,7 @@ const FileListing: FC<{ query?: ParsedUrlQuery }> = ({ query }) => {
} else if (files.length > 1) {
setTotalGenerating(true)
const toastId = toast.loading(DownloadingToast(router))
const toastId = toast.loading(<DownloadingToast router={router} />)
downloadMultipleFiles({ toastId, router, files, folder })
.then(() => {
setTotalGenerating(false)
@@ -278,7 +278,7 @@ const FileListing: FC<{ query?: ParsedUrlQuery }> = ({ query }) => {
})()
setFolderGenerating({ ...folderGenerating, [id]: true })
const toastId = toast.loading(DownloadingToast(router))
const toastId = toast.loading(<DownloadingToast router={router} />)
downloadTreelikeMultipleFiles({
toastId,
+7 -7
View File
@@ -7,12 +7,12 @@ import { fetcher } from '../utils/fetchWithSWR'
import { getStoredToken } from '../utils/protectedRouteHandler'
/**
* Generates a loading toast with file download progress support
* @param router Next router instance, used for reloading the page
* @param progress Current downloading and compression progress (returned by jszip metadata)
* @returns Toast component with loading progress
* A loading toast component with file download progress support
* @param props
* @param props.router Next router instance, used for reloading the page
* @param props.progress Current downloading and compression progress (returned by jszip metadata)
*/
export function DownloadingToast(router: NextRouter, progress?: string) {
export function DownloadingToast({ router, progress }: { router: NextRouter, progress?: string }) {
const { t } = useTranslation()
return (
@@ -84,7 +84,7 @@ export async function downloadMultipleFiles({
// Create zip file and download it
const b = await zip.generateAsync({ type: 'blob' }, metadata => {
toast.loading(DownloadingToast(router, metadata.percent.toFixed(0)), {
toast.loading(<DownloadingToast router={router} progress={metadata.percent.toFixed(0)} />, {
id: toastId,
})
})
@@ -152,7 +152,7 @@ export async function downloadTreelikeMultipleFiles({
// Create zip file and download it
const b = await zip.generateAsync({ type: 'blob' }, metadata => {
toast.loading(DownloadingToast(router, metadata.percent.toFixed(0)), {
toast.loading(<DownloadingToast router={router} progress={metadata.percent.toFixed(0)} />, {
id: toastId,
})
})