Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(client): make in-progress import/export toasts non-dismissible
Elian Doran58ab4fad432e
diff --git a/apps/client/src/services/import.spec.ts b/apps/client/src/services/import.spec.tsindex ce76a443d1..eff572c94f 100644--- a/apps/client/src/services/import.spec.ts+++ b/apps/client/src/services/import.spec.ts@@ -181,6 +181,8 @@ describe("importNotes ws handler", () => {await handler()({ type: "taskProgressCount", taskType: "importNotes", taskId: "t2", progressCount: 3, totalCount: 12 } as any);const toast = (toastService.showPersistent as any).mock.calls[0][0];expect(toast.progress).toBe(3 / 12);+ // The in-progress toast can't be dismissed — the import runs regardless, so a × would read as "cancel".+ expect(toast.dismissible).toBe(false);});it("uses phase-specific messages for the zip extraction and processing phases", async () => {@@ -214,6 +216,8 @@ describe("importNotes ws handler", () => {const toast = (toastService.showPersistent as any).mock.calls[0][0];expect(toast.timeout).toBe(5000);expect(setNote).toHaveBeenCalledWith("imp1");+ // The terminal toast re-enables dismissal, overriding the progress toast's value via the merge.+ expect(toast.dismissible).toBe(true);});it("shows a success toast but does not navigate when there is no imported note id", async () => {@@ -352,6 +356,8 @@ describe("export ws handler", () => {toast = (toastService.showPersistent as any).mock.calls.at(-1)[0];expect(toast.message).toBe("export.export_in_progress_with_total");expect(toast.progress).toBe(4 / 8);+ // The in-progress toast can't be dismissed — the export runs regardless of the toast.+ expect(toast.dismissible).toBe(false);tSpy.mockRestore();});@@ -362,6 +368,8 @@ describe("export ws handler", () => {expect(toast.id).toBe("e3");expect(toast.timeout).toBe(5000);expect(toast.progress).toBeUndefined();+ // The terminal toast re-enables dismissal, overriding the progress toast's value via the merge.+ expect(toast.dismissible).toBe(true);});});diff --git a/apps/client/src/services/import.ts b/apps/client/src/services/import.tsindex 63eccfd834..9bf2ae2301 100644--- a/apps/client/src/services/import.ts+++ b/apps/client/src/services/import.ts@@ -71,8 +71,10 @@ function makeToast(id: string, message: string): ToastOptionsWithRequiredId {message,icon: "bx bx-check",// This toast replaces the in-progress one (same id), and showPersistent merges fields rather than- // swapping the object — so clear the progress explicitly, otherwise the finished bar lingers at 100%.- progress: undefined+ // swapping the object — so reset the fields the progress toast set: clear the progress (otherwise the+ // finished bar lingers at 100%) and re-enable dismissal (the progress toast disabled it).+ progress: undefined,+ dismissible: true};}@@ -104,6 +106,8 @@ function makeProgressToast(taskId: string, progressCount: number, totalCount?: nid: taskId,icon: "bx bx-loader-circle bx-spin",message,+ // The import keeps running regardless of the toast, so don't offer a × that looks like "cancel".+ dismissible: false,...(hasTotal ? { progress: progressCount / totalCount } : {})};}@@ -203,8 +207,10 @@ function makeExportToast(id: string, message: string): ToastOptionsWithRequiredImessage,icon: "export",// This toast replaces the in-progress one (same id), and showPersistent merges fields rather than- // swapping the object — so clear the progress explicitly, otherwise the finished bar lingers at 100%.- progress: undefined+ // swapping the object — so reset the fields the progress toast set: clear the progress (otherwise the+ // finished bar lingers at 100%) and re-enable dismissal (the progress toast disabled it).+ progress: undefined,+ dismissible: true};}@@ -221,6 +227,8 @@ function makeExportProgressToast(taskId: string, progressCount: number, totalCoumessage: hasTotal? t("export.export_in_progress_with_total", { progressCount, totalCount }): t("export.preparing_export"),+ // The export keeps running regardless of the toast, so don't offer a × that looks like "cancel".+ dismissible: false,...(hasTotal ? { progress: progressCount / totalCount } : {})};}diff --git a/apps/client/src/services/toast.ts b/apps/client/src/services/toast.tsindex b67c89eb2b..68d90f5df8 100644--- a/apps/client/src/services/toast.ts+++ b/apps/client/src/services/toast.ts@@ -12,6 +12,12 @@ export interface ToastOptions {message: string;timeout?: number;progress?: number;+ /**+ * When `false`, the toast renders without its close (×) button so the user can't dismiss it. Use for+ * persistent in-progress toasts whose underlying operation keeps running regardless of the toast — a+ * dismissable × there reads as "cancel", which it isn't. Defaults to dismissable.+ */+ dismissible?: boolean;buttons?: {text: string;onClick: (api: { dismissToast: () => void }) => void;diff --git a/apps/client/src/widgets/Toast.css b/apps/client/src/widgets/Toast.cssindex 42c81a7784..aef8727f3b 100644--- a/apps/client/src/widgets/Toast.css+++ b/apps/client/src/widgets/Toast.css@@ -53,6 +53,12 @@padding: var(--bs-toast-padding-y) var(--bs-toast-padding-x);}+/* Without the close button the body would otherwise butt against the toast edge, since the body itself+ carries no inline padding in the no-title layout (it relies on the icon/close padding for breathing room). */+.toast.no-title.not-dismissible .toast-body {+ padding-inline-end: var(--bs-toast-padding-x);+}+.toast {.toast-buttons {padding: 0 var(--bs-toast-padding-x) var(--bs-toast-padding-y) var(--bs-toast-padding-x);diff --git a/apps/client/src/widgets/Toast.tsx b/apps/client/src/widgets/Toast.tsxindex c251b900a3..4553313807 100644--- a/apps/client/src/widgets/Toast.tsx+++ b/apps/client/src/widgets/Toast.tsx@@ -4,18 +4,18 @@ import clsx from "clsx";import { useEffect } from "preact/hooks";import { removeToastFromStore, ToastOptionsWithRequiredId, toasts } from "../services/toast";-import Icon from "./react/Icon";import Button from "./react/Button";+import Icon from "./react/Icon";export default function ToastContainer() {return (<div id="toast-container">{toasts.value.map(toast => <Toast key={toast.id} {...toast} />)}</div>- )+ );}-function Toast({ id, title, timeout, progress, message, icon, buttons }: ToastOptionsWithRequiredId) {+function Toast({ id, title, timeout, progress, message, icon, buttons, dismissible }: ToastOptionsWithRequiredId) {// Autohide.useEffect(() => {if (!timeout || timeout <= 0) return;@@ -27,7 +27,9 @@ function Toast({ id, title, timeout, progress, message, icon, buttons }: ToastOpremoveToastFromStore(id);}- const closeButton = (+ // `dismissible === false` hides the × entirely (the operation runs regardless of the toast, so a close+ // button there would misleadingly read as "cancel").+ const closeButton = dismissible === false ? null : (<buttontype="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"onClick={dismissToast}@@ -37,7 +39,7 @@ function Toast({ id, title, timeout, progress, message, icon, buttons }: ToastOpreturn (<div- class={clsx("toast", !title && "no-title")}+ class={clsx("toast", !title && "no-title", dismissible === false && "not-dismissible")}role="alert" aria-live="assertive" aria-atomic="true"id={`toast-${id}`}>@@ -56,7 +58,7 @@ function Toast({ id, title, timeout, progress, message, icon, buttons }: ToastOp<div class="toast-main-row"><div class="toast-icon">{toastIcon}</div><div className="toast-body">{message}</div>- <div class="toast-close">{closeButton}</div>+ {closeButton && <div class="toast-close">{closeButton}</div>}</div>)}@@ -73,5 +75,5 @@ function Toast({ id, title, timeout, progress, message, icon, buttons }: ToastOpstyle={{ width: `${(progress ?? 0) * 100}%` }}/></div>- )+ );}