Skip to content

A self-hostable bookmark-everything app (links, notes and images) with AI-based automatic tagging and full text search

fix: track import progress per-job (#2950)

Joseph Goodwin4224da4f83b8
diff --git a/apps/web/components/settings/ImportExport.tsx b/apps/web/components/settings/ImportExport.tsx
index 3d239066..7937688e 100644
--- a/apps/web/components/settings/ImportExport.tsx
+++ b/apps/web/components/settings/ImportExport.tsx
@@ -347,18 +347,18 @@ export function ImportExportRow() {
</ImportCard>
<ExportButton />
</div>
- {importProgress && (
- <div className="flex flex-col gap-2">
- <p className="shrink-0 text-sm">
- Processed {importProgress.done} of {importProgress.total} bookmarks
- </p>
- <div className="w-full">
- <Progress
- value={(importProgress.done * 100) / importProgress.total}
- />
+ {Object.entries(importProgress).map(([id, progress]) => {
+ return (
+ <div key={id} className="flex flex-col gap-2">
+ <p className="shrink-0 text-sm">
+ Processed {progress.done} of {progress.total} bookmarks
+ </p>
+ <div className="w-full">
+ <Progress value={(progress.done * 100) / progress.total} />
+ </div>
</div>
- </div>
- )}
+ );
+ })}
</div>
);
}
diff --git a/apps/web/lib/hooks/useBookmarkImport.ts b/apps/web/lib/hooks/useBookmarkImport.ts
index a8eae4fd..8169e624 100644
--- a/apps/web/lib/hooks/useBookmarkImport.ts
+++ b/apps/web/lib/hooks/useBookmarkImport.ts
@@ -1,6 +1,6 @@
"use client";
-import { useState } from "react";
+import { useState, useRef } from "react";
import { toast } from "@/components/ui/sonner";
import { useTranslation } from "@/lib/i18n/client";
import { useMutation, useQueryClient } from "@tanstack/react-query";
@@ -24,9 +24,9 @@ export function useBookmarkImport() {
const { t } = useTranslation();
const api = useTRPC();
- const [importProgress, setImportProgress] = useState<ImportProgress | null>(
- null,
- );
+ const [importProgress, setImportProgress] = useState<
+ Record<string, ImportProgress>
+ >({});
const [quotaError, setQuotaError] = useState<string | null>(null);
const queryClient = useQueryClient();
@@ -38,6 +38,7 @@ export function useBookmarkImport() {
const { mutateAsync: finalizeImportStaging } = useMutation(
api.importSessions.finalizeImportStaging.mutationOptions(),
);
+ const currentImportIds = useRef(new Map<File, string>());
const uploadBookmarkFileMutation = useMutation({
mutationFn: async ({
@@ -90,7 +91,10 @@ export function useBookmarkImport() {
await finalizeImportStaging({ importSessionId: sessionId });
},
},
- onProgress: (done, total) => setImportProgress({ done, total }),
+ onProgress: (id, done, total) => {
+ currentImportIds.current.set(file, id);
+ setImportProgress((prev) => ({ ...prev, [id]: { done, total } }));
+ },
},
{
// Use a custom parser to avoid re-parsing the file
@@ -101,8 +105,15 @@ export function useBookmarkImport() {
);
return result;
},
- onSuccess: async (result) => {
- setImportProgress(null);
+ onSuccess: async (result, variables) => {
+ setImportProgress((prev) => {
+ const next = { ...prev };
+ if (result.importSessionId) {
+ delete next[result.importSessionId];
+ }
+ return next;
+ });
+ currentImportIds.current.delete(variables.file);
if (result.counts.total === 0) {
toast({ description: "No bookmarks found in the file." });
@@ -114,8 +125,17 @@ export function useBookmarkImport() {
variant: "default",
});
},
- onError: (error) => {
- setImportProgress(null);
+ onError: (error, variables) => {
+ const id = currentImportIds.current.get(variables.file);
+ setImportProgress((prev) => {
+ const next = { ...prev };
+ if (id) {
+ delete next[id];
+ }
+ return next;
+ });
+ currentImportIds.current.delete(variables.file);
+
toast({
description: error.message,
variant: "destructive",
diff --git a/packages/shared/import-export/importer.test.ts b/packages/shared/import-export/importer.test.ts
index 16ceb0ae..ec4c669e 100644
--- a/packages/shared/import-export/importer.test.ts
+++ b/packages/shared/import-export/importer.test.ts
@@ -97,7 +97,7 @@ describe("importBookmarksFromFile", () => {
finalizeImportStaging,
createImportSession,
},
- onProgress: (d, t) => progress.push(d / t),
+ onProgress: (i, d, t) => progress.push(d / t),
},
{ parsers },
);
@@ -261,7 +261,7 @@ describe("importBookmarksFromFile", () => {
finalizeImportStaging,
createImportSession,
},
- onProgress: (d, t) => progress.push(d / t),
+ onProgress: (i, d, t) => progress.push(d / t),
},
{ parsers },
);
@@ -361,7 +361,7 @@ describe("importBookmarksFromFile", () => {
finalizeImportStaging,
createImportSession,
},
- onProgress: (d, t) => progress.push(d / t),
+ onProgress: (i, d, t) => progress.push(d / t),
},
{ parsers },
);
diff --git a/packages/shared/import-export/importer.ts b/packages/shared/import-export/importer.ts
index 117f8192..fca7bc28 100644
--- a/packages/shared/import-export/importer.ts
+++ b/packages/shared/import-export/importer.ts
@@ -65,7 +65,7 @@ export async function importBookmarksFromFile(
source: ImportSource;
rootListName: string;
deps: ImportDeps;
- onProgress?: (done: number, total: number) => void;
+ onProgress?: (id: string, done: number, total: number) => void;
},
options: ImportOptions = {},
): Promise<ImportResult> {
@@ -91,7 +91,7 @@ export async function importBookmarksFromFile(
rootListId: rootList.id,
});
- onProgress?.(0, parsedBookmarks.length);
+ onProgress?.(session.id, 0, parsedBookmarks.length);
const externalListIdToCreatedListId: Record<string, string> = {};
if (parsedLists.length > 0) {
@@ -268,7 +268,7 @@ export async function importBookmarksFromFile(
bookmarks: batch,
});
staged += batch.length;
- onProgress?.(staged, parsedBookmarks.length);
+ onProgress?.(session.id, staged, parsedBookmarks.length);
}
// Finalize staging - marks session as "pending" for worker pickup