diff --git a/app/actions/definitions/documents.tsx b/app/actions/definitions/documents.tsx index a5e828f148..91907d6289 100644 --- a/app/actions/definitions/documents.tsx +++ b/app/actions/definitions/documents.tsx @@ -729,7 +729,6 @@ export const downloadDocumentAsMarkdown = createAction({ const document = stores.documents.get(activeDocumentId); await document?.download({ contentType: ExportContentType.Markdown, - includeChildDocuments: false, }); }, }); @@ -751,7 +750,6 @@ export const downloadDocumentAsHTML = createAction({ const document = stores.documents.get(activeDocumentId); await document?.download({ contentType: ExportContentType.Html, - includeChildDocuments: false, }); }, }); @@ -774,7 +772,6 @@ export const downloadDocumentAsTextBundle = createAction({ const document = stores.documents.get(activeDocumentId); await document?.download({ contentType: ExportContentType.TextBundle, - includeChildDocuments: false, }); }, }); @@ -800,7 +797,6 @@ export const downloadDocumentAsPDF = createAction({ const document = stores.documents.get(activeDocumentId); await document?.download({ contentType: ExportContentType.Pdf, - includeChildDocuments: false, }); }, }); diff --git a/app/components/Export/ExportDialog.tsx b/app/components/Export/ExportDialog.tsx index 7e9efb392d..ff4eef7921 100644 --- a/app/components/Export/ExportDialog.tsx +++ b/app/components/Export/ExportDialog.tsx @@ -2,7 +2,6 @@ import { observer } from "mobx-react"; import { ArchiveIcon, CodeIcon } from "outline-icons"; import * as React from "react"; import { useTranslation } from "react-i18next"; -import { toast } from "sonner"; import styled from "styled-components"; import { FileOperationFormat, NotificationEventType } from "@shared/types"; import type Collection from "~/models/Collection"; @@ -60,25 +59,7 @@ export const ExportDialog = observer(({ collection, onSubmit }: Props) => { } if (response?.data?.fileOperation) { - const fileOperationId = response.data.fileOperation.id; - const toastId = `export-${fileOperationId}`; - - const timeoutId = setTimeout(() => { - toast.success(t("Export started"), { - id: toastId, - description: t("A link to your file will be sent through email soon"), - duration: 3000, - }); - ui.exportToasts.delete(fileOperationId); - }, 6000); - - ui.registerExportToast(fileOperationId, toastId, timeoutId); - - toast.loading(t("Export started"), { - id: toastId, - description: `${t("Preparing your download")}…`, - duration: Infinity, - }); + ui.showExportToast(response.data.fileOperation.id); } onSubmit(); diff --git a/app/models/Document.ts b/app/models/Document.ts index 9222bba05e..2f2bd23642 100644 --- a/app/models/Document.ts +++ b/app/models/Document.ts @@ -679,18 +679,29 @@ export default class Document extends ArchivableModel implements Searchable { ); } - download = ({ + /** + * Download the document in the given format. + * + * Nested documents are included by default when the document has children, in + * which case the file is prepared in the background and the user is notified + * with a toast once it is ready. + * + * @param options.contentType The format to export the document in. + * @param options.includeChildDocuments Whether to include nested documents. + * @returns the API response. + */ + download = async ({ contentType, - includeChildDocuments, + includeChildDocuments = this.children.length > 0, }: { contentType: ExportContentType; includeChildDocuments?: boolean; - }) => - client.post( + }) => { + const response = await client.post( `/documents.export`, { id: this.id, - includeChildDocuments: includeChildDocuments ?? false, + includeChildDocuments, }, { ...(includeChildDocuments ? {} : { download: true }), @@ -699,4 +710,12 @@ export default class Document extends ArchivableModel implements Searchable { }, } ); + + const fileOperation = response?.data?.fileOperation; + if (fileOperation) { + this.store.rootStore.ui.showExportToast(fileOperation.id); + } + + return response; + }; } diff --git a/app/stores/UiStore.ts b/app/stores/UiStore.ts index 5cde1dea0b..d0c441b007 100644 --- a/app/stores/UiStore.ts +++ b/app/stores/UiStore.ts @@ -1,6 +1,8 @@ import { clamp } from "es-toolkit"; +import { t } from "i18next"; import { action, computed, observable } from "mobx"; import { flushSync } from "react-dom"; +import { toast } from "sonner"; import { light as defaultTheme } from "@shared/styles/theme"; import type { ProsemirrorData } from "@shared/types"; import Storage from "@shared/utils/Storage"; @@ -486,13 +488,32 @@ class UiStore { this.debugSafeArea = !this.debugSafeArea; }; + /** + * Display a toast for an export that is being prepared in the background, + * it is updated in place once the export completes or fails. + * + * @param fileOperationId The identifier of the export file operation. + */ @action - registerExportToast = ( - fileOperationId: string, - toastId: string, - timeoutId: ReturnType - ) => { + showExportToast = (fileOperationId: string) => { + const toastId = `export-${fileOperationId}`; + + const timeoutId = setTimeout(() => { + toast.success(t("Export started"), { + id: toastId, + description: t("A link to your file will be sent through email soon"), + duration: 3000, + }); + this.exportToasts.delete(fileOperationId); + }, 6000); + this.exportToasts.set(fileOperationId, { toastId, timeoutId }); + + toast.loading(t("Export started"), { + id: toastId, + description: `${t("Preparing your download")}…`, + duration: Infinity, + }); }; @action diff --git a/shared/i18n/locales/en_US/translation.json b/shared/i18n/locales/en_US/translation.json index de6ffc2275..54aaeb96ae 100644 --- a/shared/i18n/locales/en_US/translation.json +++ b/shared/i18n/locales/en_US/translation.json @@ -409,9 +409,6 @@ "our engineers have been notified": "our engineers have been notified", "Clear cache + reload": "Clear cache + reload", "Show detail": "Show detail", - "Export started": "Export started", - "A link to your file will be sent through email soon": "A link to your file will be sent through email soon", - "Preparing your download": "Preparing your download", "Exporting the collection may take some time.": "Exporting the collection may take some time.", "You will receive an email when it's complete.": "You will receive an email when it's complete.", "Include attachments": "Include attachments", @@ -1518,6 +1515,9 @@ "A confirmation code has been sent to your email address, please enter the code below to permanently destroy your account.": "A confirmation code has been sent to your email address, please enter the code below to permanently destroy your account.", "Are you sure? Deleting your account will destroy identifying data associated with your user and cannot be undone. You will be immediately logged out of {{appName}} and all your API tokens will be revoked.": "Are you sure? Deleting your account will destroy identifying data associated with your user and cannot be undone. You will be immediately logged out of {{appName}} and all your API tokens will be revoked.", "Delete my account": "Delete my account", + "Export started": "Export started", + "A link to your file will be sent through email soon": "A link to your file will be sent through email soon", + "Preparing your download": "Preparing your download", "Today": "Today", "Yesterday": "Yesterday", "Last week": "Last week",