Skip to content

Build your personal knowledge base with Trilium Notes

feat(import): show a generic message before the import count is known

Elian Doran0b5a9c5d34a3
diff --git a/apps/client/src/services/import.spec.ts b/apps/client/src/services/import.spec.ts
index f6f5793d37..6e71592b24 100644
--- a/apps/client/src/services/import.spec.ts
+++ b/apps/client/src/services/import.spec.ts
@@ -160,6 +160,15 @@ describe("importNotes ws handler", () => {
expect(toast.progress).toBe(3 / 12);
});
+ it("shows a generic 'starting' message (no bar) before anything is counted", async () => {
+ const tSpy = vi.spyOn(i18n, "t").mockImplementation(((key: string) => key) as typeof i18n.t);
+ await handler()({ type: "taskProgressCount", taskType: "importNotes", taskId: "t2", progressCount: 0 } as any);
+ const toast = (toastService.showPersistent as any).mock.calls[0][0];
+ expect(toast.progress).toBeUndefined();
+ expect(toast.message).toBe("import.starting");
+ tSpy.mockRestore();
+ });
+
it("shows a success toast and navigates to the imported note when one is returned", async () => {
await handler()({
type: "taskSucceeded",
diff --git a/apps/client/src/services/import.ts b/apps/client/src/services/import.ts
index ede568c224..a0cc992587 100644
--- a/apps/client/src/services/import.ts
+++ b/apps/client/src/services/import.ts
@@ -67,17 +67,27 @@ function makeToast(id: string, message: string): ToastOptionsWithRequiredId {
}
/**
- * Builds the persistent "import in progress" toast. When the task reported a total up front, it shows
- * an "X of N" message with a progress bar; otherwise it falls back to a bare running count.
+ * Builds the persistent "import in progress" toast:
+ * - a total is known → "Importing X of N" with a progress bar;
+ * - some progress, no total → a bare running count;
+ * - nothing counted yet (count 0, no total) → a generic indeterminate message, since "in progress: 0"
+ * is meaningless while the importer is still working out how much there is to do.
*/
function makeProgressToast(taskId: string, progressCount: number, totalCount?: number): ToastOptionsWithRequiredId {
const hasTotal = typeof totalCount === "number" && totalCount > 0;
+ let message: string;
+ if (hasTotal) {
+ message = t("import.in-progress-with-total", { progress: progressCount, total: totalCount });
+ } else if (progressCount > 0) {
+ message = t("import.in-progress", { progress: progressCount });
+ } else {
+ message = t("import.starting");
+ }
+
return {
id: taskId,
icon: "bx bx-loader-circle bx-spin",
- message: hasTotal
- ? t("import.in-progress-with-total", { progress: progressCount, total: totalCount })
- : t("import.in-progress", { progress: progressCount }),
+ message,
...(hasTotal ? { progress: progressCount / totalCount } : {})
};
}
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index a1329e8053..dae60a5c89 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -224,6 +224,7 @@
"placeholder": "Enter HTML tags, one per line",
"reset_button": "Reset to Default List"
},
+ "starting": "Importing…",
"in-progress": "Import in progress: {{progress}}",
"in-progress-with-total": "Importing {{progress}} of {{total}}",
"successful": "Import finished successfully."