chore: fix downloads

This commit is contained in:
Aman Harwara
2023-04-25 14:46:24 +05:30
parent 70fd47a697
commit d08581c8a6
2 changed files with 25 additions and 3 deletions

View File

@@ -1,6 +1,7 @@
import { FilesController } from '@/Controllers/FilesController'
import { NoPreviewIllustration } from '@standardnotes/icons'
import { FileItem } from '@standardnotes/snjs'
import { FileItemActionType } from '../AttachedFilesPopover/PopoverFileItemAction'
import Button from '../Button/Button'
type Props = {
@@ -32,7 +33,14 @@ const FilePreviewError = ({ file, filesController, isFilePreviewable, tryAgainCa
</Button>
<Button
onClick={() => {
filesController.downloadFile(file).catch(console.error)
filesController
.handleFileAction({
type: FileItemActionType.DownloadFile,
payload: {
file,
},
})
.catch(console.error)
}}
>
Download
@@ -47,7 +55,12 @@ const FilePreviewError = ({ file, filesController, isFilePreviewable, tryAgainCa
<Button
primary
onClick={() => {
filesController.downloadFile(file).catch(console.error)
filesController
.handleFileAction({
type: FileItemActionType.DownloadFile,
payload: { file },
})
.catch(console.error)
}}
>
Download

View File

@@ -498,6 +498,15 @@ export class FilesController extends AbstractViewController<FilesControllerEvent
}
downloadFiles = async (files: FileItem[]) => {
await Promise.all(files.map((file) => this.downloadFile(file)))
await Promise.all(
files.map((file) =>
this.handleFileAction({
type: FileItemActionType.DownloadFile,
payload: {
file,
},
}),
),
)
}
}