aboutsummaryrefslogtreecommitdiffstats
path: root/apps/web/lib/hooks/useImportSessions.ts
diff options
context:
space:
mode:
authorMohamed Bassem <me@mbassem.com>2025-10-04 13:40:24 +0100
committerGitHub <noreply@github.com>2025-10-04 13:40:24 +0100
commit4a580d713621f99abb8baabc9b847ce039d44842 (patch)
treea2aa6f3ae8045ad50a9316624e2a7028dd098c6b /apps/web/lib/hooks/useImportSessions.ts
parent5e331a7d5b8d9666812170547574804d8b6da741 (diff)
downloadkarakeep-4a580d713621f99abb8baabc9b847ce039d44842.tar.zst
feat: Revamp import experience (#2001)
* WIP: import v2 * remove new session button * don't redirect after import * store and lint to root list * models + tests * redesign the progress * simplify the import session for ow * drop status from session schema * split the import session page * i18n * fix test * remove pagination * fix some colors in darkmode * one last fix * add privacy filter * privacy check * fix interactivity of import progress * fix test
Diffstat (limited to 'apps/web/lib/hooks/useImportSessions.ts')
-rw-r--r--apps/web/lib/hooks/useImportSessions.ts62
1 files changed, 62 insertions, 0 deletions
diff --git a/apps/web/lib/hooks/useImportSessions.ts b/apps/web/lib/hooks/useImportSessions.ts
new file mode 100644
index 00000000..cee99bbc
--- /dev/null
+++ b/apps/web/lib/hooks/useImportSessions.ts
@@ -0,0 +1,62 @@
+"use client";
+
+import { toast } from "@/components/ui/use-toast";
+
+import { api } from "@karakeep/shared-react/trpc";
+
+export function useCreateImportSession() {
+ const apiUtils = api.useUtils();
+
+ return api.importSessions.createImportSession.useMutation({
+ onSuccess: () => {
+ apiUtils.importSessions.listImportSessions.invalidate();
+ },
+ onError: (error) => {
+ toast({
+ description: error.message || "Failed to create import session",
+ variant: "destructive",
+ });
+ },
+ });
+}
+
+export function useListImportSessions() {
+ return api.importSessions.listImportSessions.useQuery(
+ {},
+ {
+ select: (data) => data.sessions,
+ },
+ );
+}
+
+export function useImportSessionStats(importSessionId: string) {
+ return api.importSessions.getImportSessionStats.useQuery(
+ {
+ importSessionId,
+ },
+ {
+ refetchInterval: 5000, // Refetch every 5 seconds to show progress
+ enabled: !!importSessionId,
+ },
+ );
+}
+
+export function useDeleteImportSession() {
+ const apiUtils = api.useUtils();
+
+ return api.importSessions.deleteImportSession.useMutation({
+ onSuccess: () => {
+ apiUtils.importSessions.listImportSessions.invalidate();
+ toast({
+ description: "Import session deleted successfully",
+ variant: "default",
+ });
+ },
+ onError: (error) => {
+ toast({
+ description: error.message || "Failed to delete import session",
+ variant: "destructive",
+ });
+ },
+ });
+}