From 65f6e83f11c82b0ec762e11f3392a80e614ee69a Mon Sep 17 00:00:00 2001
From: Mohamed Bassem
Date: Sun, 1 Feb 2026 12:29:54 +0000
Subject: refactor: migrate trpc to the new react query integration mode
(#2438)
* refactor: migrate trpc to the new react query integration mode
* more fixes
* more migrations
* upgrade trpc client
---
apps/web/app/check-email/page.tsx | 26 +-
apps/web/app/reader/[bookmarkId]/page.tsx | 20 +-
apps/web/app/settings/assets/page.tsx | 20 +-
apps/web/app/settings/broken-links/page.tsx | 16 +-
apps/web/app/settings/rules/page.tsx | 14 +-
apps/web/app/settings/stats/page.tsx | 12 +-
apps/web/app/verify-email/page.tsx | 58 +--
apps/web/components/admin/AddUserDialog.tsx | 430 +++++++++++----------
apps/web/components/admin/AdminNotices.tsx | 6 +-
apps/web/components/admin/BackgroundJobs.tsx | 131 ++++---
apps/web/components/admin/BasicStats.tsx | 13 +-
apps/web/components/admin/BookmarkDebugger.tsx | 116 +++---
apps/web/components/admin/CreateInviteDialog.tsx | 44 ++-
apps/web/components/admin/InvitesList.tsx | 30 +-
apps/web/components/admin/ResetPasswordDialog.tsx | 294 +++++++-------
apps/web/components/admin/ServiceConnections.tsx | 12 +-
apps/web/components/admin/UpdateUserDialog.tsx | 48 +--
apps/web/components/admin/UserList.tsx | 27 +-
.../dashboard/bookmarks/BookmarkCard.tsx | 32 +-
.../bookmarks/BookmarkLayoutAdaptingCard.tsx | 22 +-
.../dashboard/bookmarks/BulkTagModal.tsx | 12 +-
.../dashboard/bookmarks/EditBookmarkDialog.tsx | 11 +-
.../dashboard/bookmarks/ManageListsModal.tsx | 11 +-
.../components/dashboard/bookmarks/TagsEditor.tsx | 12 +-
.../dashboard/bookmarks/UpdatableBookmarksGrid.tsx | 28 +-
.../action-buttons/ArchiveBookmarkButton.tsx | 20 +-
.../dashboard/cleanups/TagDuplicationDetention.tsx | 16 +-
.../components/dashboard/feeds/FeedSelector.tsx | 12 +-
.../dashboard/highlights/AllHighlights.tsx | 48 ++-
.../dashboard/lists/CollapsibleBookmarkLists.tsx | 13 +-
.../lists/LeaveListConfirmationDialog.tsx | 54 +--
apps/web/components/dashboard/lists/ListHeader.tsx | 38 +-
.../dashboard/lists/ManageCollaboratorsModal.tsx | 154 ++++----
.../dashboard/lists/PendingInvitationsCard.tsx | 83 ++--
apps/web/components/dashboard/lists/RssLink.tsx | 33 +-
.../dashboard/preview/BookmarkPreview.tsx | 32 +-
.../components/dashboard/preview/HighlightsBox.tsx | 9 +-
.../components/dashboard/preview/ReaderView.tsx | 19 +-
.../dashboard/search/useSearchAutocomplete.ts | 12 +-
.../sidebar/InvitationNotificationBadge.tsx | 11 +-
.../components/dashboard/tags/TagAutocomplete.tsx | 11 +-
apps/web/components/invite/InviteAcceptForm.tsx | 10 +-
.../components/public/lists/PublicBookmarkGrid.tsx | 28 +-
apps/web/components/settings/AISettings.tsx | 44 ++-
apps/web/components/settings/AddApiKey.tsx | 30 +-
apps/web/components/settings/BackupSettings.tsx | 47 ++-
apps/web/components/settings/ChangePassword.tsx | 41 +-
apps/web/components/settings/DeleteApiKey.tsx | 18 +-
apps/web/components/settings/FeedSettings.tsx | 85 ++--
apps/web/components/settings/RegenerateApiKey.tsx | 32 +-
.../components/settings/SubscriptionSettings.tsx | 31 +-
apps/web/components/settings/WebhookSettings.tsx | 56 +--
apps/web/components/signin/ForgotPasswordForm.tsx | 8 +-
apps/web/components/signin/ResetPasswordForm.tsx | 8 +-
apps/web/components/signup/SignUpForm.tsx | 6 +-
apps/web/components/subscription/QuotaProgress.tsx | 9 +-
apps/web/components/utils/ValidAccountCheck.tsx | 22 +-
apps/web/components/wrapped/WrappedModal.tsx | 20 +-
apps/web/lib/hooks/bookmark-search.ts | 29 +-
apps/web/lib/hooks/useBookmarkImport.ts | 12 +-
apps/web/lib/hooks/useImportSessions.ts | 105 ++---
apps/web/lib/providers.tsx | 15 +-
apps/web/lib/trpc.tsx | 8 +-
apps/web/lib/userSettings.tsx | 12 +-
apps/web/package.json | 6 +-
65 files changed, 1513 insertions(+), 1179 deletions(-)
(limited to 'apps/web')
diff --git a/apps/web/app/check-email/page.tsx b/apps/web/app/check-email/page.tsx
index 227e116c..9e6a37b8 100644
--- a/apps/web/app/check-email/page.tsx
+++ b/apps/web/app/check-email/page.tsx
@@ -11,26 +11,30 @@ import {
CardHeader,
CardTitle,
} from "@/components/ui/card";
-import { api } from "@/lib/trpc";
+import { useTRPC } from "@/lib/trpc";
+import { useMutation } from "@tanstack/react-query";
import { Loader2, Mail } from "lucide-react";
export default function CheckEmailPage() {
+ const api = useTRPC();
const searchParams = useSearchParams();
const router = useRouter();
const [message, setMessage] = useState("");
const email = searchParams.get("email");
- const resendEmailMutation = api.users.resendVerificationEmail.useMutation({
- onSuccess: () => {
- setMessage(
- "A new verification email has been sent to your email address.",
- );
- },
- onError: (error) => {
- setMessage(error.message || "Failed to resend verification email.");
- },
- });
+ const resendEmailMutation = useMutation(
+ api.users.resendVerificationEmail.mutationOptions({
+ onSuccess: () => {
+ setMessage(
+ "A new verification email has been sent to your email address.",
+ );
+ },
+ onError: (error) => {
+ setMessage(error.message || "Failed to resend verification email.");
+ },
+ }),
+ );
const handleResendEmail = () => {
if (email) {
diff --git a/apps/web/app/reader/[bookmarkId]/page.tsx b/apps/web/app/reader/[bookmarkId]/page.tsx
index 3eba7c7a..0ba72016 100644
--- a/apps/web/app/reader/[bookmarkId]/page.tsx
+++ b/apps/web/app/reader/[bookmarkId]/page.tsx
@@ -10,22 +10,28 @@ import { FullPageSpinner } from "@/components/ui/full-page-spinner";
import { Separator } from "@/components/ui/separator";
import { useSession } from "@/lib/auth/client";
import { useReaderSettings } from "@/lib/readerSettings";
+import { useQuery } from "@tanstack/react-query";
import { HighlighterIcon as Highlight, Printer, X } from "lucide-react";
-import { api } from "@karakeep/shared-react/trpc";
+import { useTRPC } from "@karakeep/shared-react/trpc";
import { BookmarkTypes } from "@karakeep/shared/types/bookmarks";
import { READER_FONT_FAMILIES } from "@karakeep/shared/types/readers";
import { getBookmarkTitle } from "@karakeep/shared/utils/bookmarkUtils";
export default function ReaderViewPage() {
+ const api = useTRPC();
const params = useParams<{ bookmarkId: string }>();
const bookmarkId = params.bookmarkId;
- const { data: highlights } = api.highlights.getForBookmark.useQuery({
- bookmarkId,
- });
- const { data: bookmark } = api.bookmarks.getBookmark.useQuery({
- bookmarkId,
- });
+ const { data: highlights } = useQuery(
+ api.highlights.getForBookmark.queryOptions({
+ bookmarkId,
+ }),
+ );
+ const { data: bookmark } = useQuery(
+ api.bookmarks.getBookmark.queryOptions({
+ bookmarkId,
+ }),
+ );
const { data: session } = useSession();
const router = useRouter();
diff --git a/apps/web/app/settings/assets/page.tsx b/apps/web/app/settings/assets/page.tsx
index a2d2c9ab..0991816c 100644
--- a/apps/web/app/settings/assets/page.tsx
+++ b/apps/web/app/settings/assets/page.tsx
@@ -16,8 +16,9 @@ import {
} from "@/components/ui/table";
import { ASSET_TYPE_TO_ICON } from "@/lib/attachments";
import { useTranslation } from "@/lib/i18n/client";
-import { api } from "@/lib/trpc";
+import { useTRPC } from "@/lib/trpc";
import { formatBytes } from "@/lib/utils";
+import { useInfiniteQuery } from "@tanstack/react-query";
import { ExternalLink, Trash2 } from "lucide-react";
import { useDetachBookmarkAsset } from "@karakeep/shared-react/hooks/assets";
@@ -28,6 +29,7 @@ import {
} from "@karakeep/trpc/lib/attachments";
export default function AssetsSettingsPage() {
+ const api = useTRPC();
const { t } = useTranslation();
const { mutate: detachAsset, isPending: isDetaching } =
useDetachBookmarkAsset({
@@ -49,13 +51,15 @@ export default function AssetsSettingsPage() {
fetchNextPage,
hasNextPage,
isFetchingNextPage,
- } = api.assets.list.useInfiniteQuery(
- {
- limit: 20,
- },
- {
- getNextPageParam: (lastPage) => lastPage.nextCursor,
- },
+ } = useInfiniteQuery(
+ api.assets.list.infiniteQueryOptions(
+ {
+ limit: 20,
+ },
+ {
+ getNextPageParam: (lastPage) => lastPage.nextCursor,
+ },
+ ),
);
const assets = data?.pages.flatMap((page) => page.assets) ?? [];
diff --git a/apps/web/app/settings/broken-links/page.tsx b/apps/web/app/settings/broken-links/page.tsx
index 139e8f91..4197d62e 100644
--- a/apps/web/app/settings/broken-links/page.tsx
+++ b/apps/web/app/settings/broken-links/page.tsx
@@ -11,6 +11,7 @@ import {
TableHeader,
TableRow,
} from "@/components/ui/table";
+import { useQuery, useQueryClient } from "@tanstack/react-query";
import { RefreshCw, Trash2 } from "lucide-react";
import { useTranslation } from "react-i18next";
@@ -18,20 +19,23 @@ import {
useDeleteBookmark,
useRecrawlBookmark,
} from "@karakeep/shared-react/hooks/bookmarks";
-import { api } from "@karakeep/shared-react/trpc";
+import { useTRPC } from "@karakeep/shared-react/trpc";
export default function BrokenLinksPage() {
+ const api = useTRPC();
const { t } = useTranslation();
- const apiUtils = api.useUtils();
- const { data, isPending } = api.bookmarks.getBrokenLinks.useQuery();
+ const queryClient = useQueryClient();
+ const { data, isPending } = useQuery(
+ api.bookmarks.getBrokenLinks.queryOptions(),
+ );
const { mutate: deleteBookmark, isPending: isDeleting } = useDeleteBookmark({
onSuccess: () => {
toast({
description: t("toasts.bookmarks.deleted"),
});
- apiUtils.bookmarks.getBrokenLinks.invalidate();
+ queryClient.invalidateQueries(api.bookmarks.getBrokenLinks.pathFilter());
},
onError: () => {
toast({
@@ -47,7 +51,9 @@ export default function BrokenLinksPage() {
toast({
description: t("toasts.bookmarks.refetch"),
});
- apiUtils.bookmarks.getBrokenLinks.invalidate();
+ queryClient.invalidateQueries(
+ api.bookmarks.getBrokenLinks.pathFilter(),
+ );
},
onError: () => {
toast({
diff --git a/apps/web/app/settings/rules/page.tsx b/apps/web/app/settings/rules/page.tsx
index 17f5b388..6d0b6522 100644
--- a/apps/web/app/settings/rules/page.tsx
+++ b/apps/web/app/settings/rules/page.tsx
@@ -6,21 +6,25 @@ import RuleList from "@/components/dashboard/rules/RuleEngineRuleList";
import { Button } from "@/components/ui/button";
import { FullPageSpinner } from "@/components/ui/full-page-spinner";
import { useTranslation } from "@/lib/i18n/client";
-import { api } from "@/lib/trpc";
+import { useTRPC } from "@/lib/trpc";
+import { useQuery } from "@tanstack/react-query";
import { PlusCircle } from "lucide-react";
import { RuleEngineRule } from "@karakeep/shared/types/rules";
export default function RulesSettingsPage() {
+ const api = useTRPC();
const { t } = useTranslation();
const [editingRule, setEditingRule] = useState<
(Omit & { id: string | null }) | null
>(null);
- const { data: rules, isLoading } = api.rules.list.useQuery(undefined, {
- refetchOnWindowFocus: true,
- refetchOnMount: true,
- });
+ const { data: rules, isLoading } = useQuery(
+ api.rules.list.queryOptions(undefined, {
+ refetchOnWindowFocus: true,
+ refetchOnMount: true,
+ }),
+ );
const handleCreateRule = () => {
const newRule = {
diff --git a/apps/web/app/settings/stats/page.tsx b/apps/web/app/settings/stats/page.tsx
index 28c017f5..06076376 100644
--- a/apps/web/app/settings/stats/page.tsx
+++ b/apps/web/app/settings/stats/page.tsx
@@ -6,7 +6,8 @@ import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Progress } from "@/components/ui/progress";
import { Skeleton } from "@/components/ui/skeleton";
import { useTranslation } from "@/lib/i18n/client";
-import { api } from "@/lib/trpc";
+import { useTRPC } from "@/lib/trpc";
+import { useQuery } from "@tanstack/react-query";
import {
Archive,
BarChart3,
@@ -159,9 +160,10 @@ function StatCard({
}
export default function StatsPage() {
+ const api = useTRPC();
const { t } = useTranslation();
- const { data: stats, isLoading } = api.users.stats.useQuery();
- const { data: userSettings } = api.users.settings.useQuery();
+ const { data: stats, isLoading } = useQuery(api.users.stats.queryOptions());
+ const { data: userSettings } = useQuery(api.users.settings.queryOptions());
const maxHourlyActivity = useMemo(() => {
if (!stats) return 0;
@@ -237,7 +239,6 @@ export default function StatsPage() {
-
{/* Overview Stats */}
-
{/* Bookmark Types */}
@@ -532,7 +532,6 @@ export default function StatsPage() {
-
{/* Activity Patterns */}
{/* Hourly Activity */}
@@ -583,7 +582,6 @@ export default function StatsPage() {
-
{/* Asset Storage */}
{stats.assetsByType.length > 0 && (
diff --git a/apps/web/app/verify-email/page.tsx b/apps/web/app/verify-email/page.tsx
index da9b8b6b..7da96761 100644
--- a/apps/web/app/verify-email/page.tsx
+++ b/apps/web/app/verify-email/page.tsx
@@ -11,10 +11,12 @@ import {
CardHeader,
CardTitle,
} from "@/components/ui/card";
-import { api } from "@/lib/trpc";
+import { useTRPC } from "@/lib/trpc";
+import { useMutation } from "@tanstack/react-query";
import { CheckCircle, Loader2, XCircle } from "lucide-react";
export default function VerifyEmailPage() {
+ const api = useTRPC();
const searchParams = useSearchParams();
const router = useRouter();
const [status, setStatus] = useState<"loading" | "success" | "error">(
@@ -25,32 +27,36 @@ export default function VerifyEmailPage() {
const token = searchParams.get("token");
const email = searchParams.get("email");
- const verifyEmailMutation = api.users.verifyEmail.useMutation({
- onSuccess: () => {
- setStatus("success");
- setMessage(
- "Your email has been successfully verified! You can now sign in.",
- );
- },
- onError: (error) => {
- setStatus("error");
- setMessage(
- error.message ||
- "Failed to verify email. The link may be invalid or expired.",
- );
- },
- });
+ const verifyEmailMutation = useMutation(
+ api.users.verifyEmail.mutationOptions({
+ onSuccess: () => {
+ setStatus("success");
+ setMessage(
+ "Your email has been successfully verified! You can now sign in.",
+ );
+ },
+ onError: (error) => {
+ setStatus("error");
+ setMessage(
+ error.message ||
+ "Failed to verify email. The link may be invalid or expired.",
+ );
+ },
+ }),
+ );
- const resendEmailMutation = api.users.resendVerificationEmail.useMutation({
- onSuccess: () => {
- setMessage(
- "A new verification email has been sent to your email address.",
- );
- },
- onError: (error) => {
- setMessage(error.message || "Failed to resend verification email.");
- },
- });
+ const resendEmailMutation = useMutation(
+ api.users.resendVerificationEmail.mutationOptions({
+ onSuccess: () => {
+ setMessage(
+ "A new verification email has been sent to your email address.",
+ );
+ },
+ onError: (error) => {
+ setMessage(error.message || "Failed to resend verification email.");
+ },
+ }),
+ );
useEffect(() => {
if (token && email) {
diff --git a/apps/web/components/admin/AddUserDialog.tsx b/apps/web/components/admin/AddUserDialog.tsx
index 3c578eca..2e29c6da 100644
--- a/apps/web/components/admin/AddUserDialog.tsx
+++ b/apps/web/components/admin/AddUserDialog.tsx
@@ -1,213 +1,217 @@
-import { useEffect, useState } from "react";
-import { ActionButton } from "@/components/ui/action-button";
-import { Button } from "@/components/ui/button";
-import {
- Dialog,
- DialogClose,
- DialogContent,
- DialogFooter,
- DialogHeader,
- DialogTitle,
- DialogTrigger,
-} from "@/components/ui/dialog";
-import {
- Form,
- FormControl,
- FormField,
- FormItem,
- FormLabel,
- FormMessage,
-} from "@/components/ui/form";
-import { Input } from "@/components/ui/input";
-import {
- Select,
- SelectContent,
- SelectItem,
- SelectTrigger,
- SelectValue,
-} from "@/components/ui/select";
-import { toast } from "@/components/ui/sonner";
-import { api } from "@/lib/trpc";
-import { zodResolver } from "@hookform/resolvers/zod";
-import { TRPCClientError } from "@trpc/client";
-import { useForm } from "react-hook-form";
-import { z } from "zod";
-
-import { zAdminCreateUserSchema } from "@karakeep/shared/types/admin";
-
-type AdminCreateUserSchema = z.infer;
-
-export default function AddUserDialog({
- children,
-}: {
- children?: React.ReactNode;
-}) {
- const apiUtils = api.useUtils();
- const [isOpen, onOpenChange] = useState(false);
- const form = useForm({
- resolver: zodResolver(zAdminCreateUserSchema),
- defaultValues: {
- name: "",
- email: "",
- password: "",
- confirmPassword: "",
- role: "user",
- },
- });
- const { mutate, isPending } = api.admin.createUser.useMutation({
- onSuccess: () => {
- toast({
- description: "User created successfully",
- });
- onOpenChange(false);
- apiUtils.users.list.invalidate();
- apiUtils.admin.userStats.invalidate();
- },
- onError: (error) => {
- if (error instanceof TRPCClientError) {
- toast({
- variant: "destructive",
- description: error.message,
- });
- } else {
- toast({
- variant: "destructive",
- description: "Failed to create user",
- });
- }
- },
- });
-
- useEffect(() => {
- if (!isOpen) {
- form.reset();
- }
- }, [isOpen, form]);
-
- return (
-
- );
-}
+import { useEffect, useState } from "react";
+import { ActionButton } from "@/components/ui/action-button";
+import { Button } from "@/components/ui/button";
+import {
+ Dialog,
+ DialogClose,
+ DialogContent,
+ DialogFooter,
+ DialogHeader,
+ DialogTitle,
+ DialogTrigger,
+} from "@/components/ui/dialog";
+import {
+ Form,
+ FormControl,
+ FormField,
+ FormItem,
+ FormLabel,
+ FormMessage,
+} from "@/components/ui/form";
+import { Input } from "@/components/ui/input";
+import {
+ Select,
+ SelectContent,
+ SelectItem,
+ SelectTrigger,
+ SelectValue,
+} from "@/components/ui/select";
+import { toast } from "@/components/ui/sonner";
+import { useTRPC } from "@/lib/trpc";
+import { zodResolver } from "@hookform/resolvers/zod";
+import { useMutation, useQueryClient } from "@tanstack/react-query";
+import { TRPCClientError } from "@trpc/client";
+import { useForm } from "react-hook-form";
+import { z } from "zod";
+
+import { zAdminCreateUserSchema } from "@karakeep/shared/types/admin";
+
+type AdminCreateUserSchema = z.infer;
+
+export default function AddUserDialog({
+ children,
+}: {
+ children?: React.ReactNode;
+}) {
+ const api = useTRPC();
+ const queryClient = useQueryClient();
+ const [isOpen, onOpenChange] = useState(false);
+ const form = useForm({
+ resolver: zodResolver(zAdminCreateUserSchema),
+ defaultValues: {
+ name: "",
+ email: "",
+ password: "",
+ confirmPassword: "",
+ role: "user",
+ },
+ });
+ const { mutate, isPending } = useMutation(
+ api.admin.createUser.mutationOptions({
+ onSuccess: () => {
+ toast({
+ description: "User created successfully",
+ });
+ onOpenChange(false);
+ queryClient.invalidateQueries(api.users.list.pathFilter());
+ queryClient.invalidateQueries(api.admin.userStats.pathFilter());
+ },
+ onError: (error) => {
+ if (error instanceof TRPCClientError) {
+ toast({
+ variant: "destructive",
+ description: error.message,
+ });
+ } else {
+ toast({
+ variant: "destructive",
+ description: "Failed to create user",
+ });
+ }
+ },
+ }),
+ );
+
+ useEffect(() => {
+ if (!isOpen) {
+ form.reset();
+ }
+ }, [isOpen, form]);
+
+ return (
+
+ );
+}
diff --git a/apps/web/components/admin/AdminNotices.tsx b/apps/web/components/admin/AdminNotices.tsx
index 77b1b481..e9d9a692 100644
--- a/apps/web/components/admin/AdminNotices.tsx
+++ b/apps/web/components/admin/AdminNotices.tsx
@@ -2,7 +2,8 @@
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
import { Badge } from "@/components/ui/badge";
-import { api } from "@/lib/trpc";
+import { useTRPC } from "@/lib/trpc";
+import { useQuery } from "@tanstack/react-query";
import { AlertCircle } from "lucide-react";
import { AdminCard } from "./AdminCard";
@@ -14,7 +15,8 @@ interface AdminNotice {
}
function useAdminNotices() {
- const { data } = api.admin.getAdminNoticies.useQuery();
+ const api = useTRPC();
+ const { data } = useQuery(api.admin.getAdminNoticies.queryOptions());
if (!data) {
return [];
}
diff --git a/apps/web/components/admin/BackgroundJobs.tsx b/apps/web/components/admin/BackgroundJobs.tsx
index 382069c8..3dab3c54 100644
--- a/apps/web/components/admin/BackgroundJobs.tsx
+++ b/apps/web/components/admin/BackgroundJobs.tsx
@@ -13,8 +13,8 @@ import {
import { Skeleton } from "@/components/ui/skeleton";
import { toast } from "@/components/ui/sonner";
import { useTranslation } from "@/lib/i18n/client";
-import { api } from "@/lib/trpc";
-import { keepPreviousData } from "@tanstack/react-query";
+import { useTRPC } from "@/lib/trpc";
+import { keepPreviousData, useMutation, useQuery } from "@tanstack/react-query";
import {
Activity,
AlertTriangle,
@@ -254,13 +254,51 @@ function JobCard({
}
function useJobActions() {
+ const api = useTRPC();
const { t } = useTranslation();
const { mutateAsync: recrawlLinks, isPending: isRecrawlPending } =
- api.admin.recrawlLinks.useMutation({
+ useMutation(
+ api.admin.recrawlLinks.mutationOptions({
+ onSuccess: () => {
+ toast({
+ description: "Recrawl enqueued",
+ });
+ },
+ onError: (e) => {
+ toast({
+ variant: "destructive",
+ description: e.message,
+ });
+ },
+ }),
+ );
+
+ const { mutateAsync: reindexBookmarks, isPending: isReindexPending } =
+ useMutation(
+ api.admin.reindexAllBookmarks.mutationOptions({
+ onSuccess: () => {
+ toast({
+ description: "Reindex enqueued",
+ });
+ },
+ onError: (e) => {
+ toast({
+ variant: "destructive",
+ description: e.message,
+ });
+ },
+ }),
+ );
+
+ const {
+ mutateAsync: reprocessAssetsFixMode,
+ isPending: isReprocessingPending,
+ } = useMutation(
+ api.admin.reprocessAssetsFixMode.mutationOptions({
onSuccess: () => {
toast({
- description: "Recrawl enqueued",
+ description: "Reprocessing enqueued",
});
},
onError: (e) => {
@@ -269,13 +307,17 @@ function useJobActions() {
description: e.message,
});
},
- });
+ }),
+ );
- const { mutateAsync: reindexBookmarks, isPending: isReindexPending } =
- api.admin.reindexAllBookmarks.useMutation({
+ const {
+ mutateAsync: reRunInferenceOnAllBookmarks,
+ isPending: isInferencePending,
+ } = useMutation(
+ api.admin.reRunInferenceOnAllBookmarks.mutationOptions({
onSuccess: () => {
toast({
- description: "Reindex enqueued",
+ description: "Inference jobs enqueued",
});
},
onError: (e) => {
@@ -284,58 +326,27 @@ function useJobActions() {
description: e.message,
});
},
- });
-
- const {
- mutateAsync: reprocessAssetsFixMode,
- isPending: isReprocessingPending,
- } = api.admin.reprocessAssetsFixMode.useMutation({
- onSuccess: () => {
- toast({
- description: "Reprocessing enqueued",
- });
- },
- onError: (e) => {
- toast({
- variant: "destructive",
- description: e.message,
- });
- },
- });
-
- const {
- mutateAsync: reRunInferenceOnAllBookmarks,
- isPending: isInferencePending,
- } = api.admin.reRunInferenceOnAllBookmarks.useMutation({
- onSuccess: () => {
- toast({
- description: "Inference jobs enqueued",
- });
- },
- onError: (e) => {
- toast({
- variant: "destructive",
- description: e.message,
- });
- },
- });
+ }),
+ );
const {
mutateAsync: runAdminMaintenanceTask,
isPending: isAdminMaintenancePending,
- } = api.admin.runAdminMaintenanceTask.useMutation({
- onSuccess: () => {
- toast({
- description: "Admin maintenance request has been enqueued!",
- });
- },
- onError: (e) => {
- toast({
- variant: "destructive",
- description: e.message,
- });
- },
- });
+ } = useMutation(
+ api.admin.runAdminMaintenanceTask.mutationOptions({
+ onSuccess: () => {
+ toast({
+ description: "Admin maintenance request has been enqueued!",
+ });
+ },
+ onError: (e) => {
+ toast({
+ variant: "destructive",
+ description: e.message,
+ });
+ },
+ }),
+ );
return {
crawlActions: [
@@ -466,13 +477,13 @@ function useJobActions() {
}
export default function BackgroundJobs() {
+ const api = useTRPC();
const { t } = useTranslation();
- const { data: serverStats } = api.admin.backgroundJobsStats.useQuery(
- undefined,
- {
+ const { data: serverStats } = useQuery(
+ api.admin.backgroundJobsStats.queryOptions(undefined, {
refetchInterval: 1000,
placeholderData: keepPreviousData,
- },
+ }),
);
const actions = useJobActions();
diff --git a/apps/web/components/admin/BasicStats.tsx b/apps/web/components/admin/BasicStats.tsx
index 67352f66..9c88ba83 100644
--- a/apps/web/components/admin/BasicStats.tsx
+++ b/apps/web/components/admin/BasicStats.tsx
@@ -3,7 +3,7 @@
import { AdminCard } from "@/components/admin/AdminCard";
import { useClientConfig } from "@/lib/clientConfig";
import { useTranslation } from "@/lib/i18n/client";
-import { api } from "@/lib/trpc";
+import { useTRPC } from "@/lib/trpc";
import { useQuery } from "@tanstack/react-query";
const REPO_LATEST_RELEASE_API =
@@ -42,7 +42,7 @@ function ReleaseInfo() {
rel="noreferrer"
title="Update available"
>
- ({latestRelease} ⬆️)
+ ({latestRelease}⬆️)
);
}
@@ -71,10 +71,13 @@ function StatsSkeleton() {
}
export default function BasicStats() {
+ const api = useTRPC();
const { t } = useTranslation();
- const { data: serverStats } = api.admin.stats.useQuery(undefined, {
- refetchInterval: 5000,
- });
+ const { data: serverStats } = useQuery(
+ api.admin.stats.queryOptions(undefined, {
+ refetchInterval: 5000,
+ }),
+ );
if (!serverStats) {
return ;
diff --git a/apps/web/components/admin/BookmarkDebugger.tsx b/apps/web/components/admin/BookmarkDebugger.tsx
index 1628fdcc..78eb2c85 100644
--- a/apps/web/components/admin/BookmarkDebugger.tsx
+++ b/apps/web/components/admin/BookmarkDebugger.tsx
@@ -8,8 +8,9 @@ import { Button } from "@/components/ui/button";
import InfoTooltip from "@/components/ui/info-tooltip";
import { Input } from "@/components/ui/input";
import { useTranslation } from "@/lib/i18n/client";
-import { api } from "@/lib/trpc";
+import { useTRPC } from "@/lib/trpc";
import { formatBytes } from "@/lib/utils";
+import { useMutation, useQuery } from "@tanstack/react-query";
import { formatDistanceToNow } from "date-fns";
import {
AlertCircle,
@@ -37,6 +38,7 @@ import { toast } from "sonner";
import { BookmarkTypes } from "@karakeep/shared/types/bookmarks";
export default function BookmarkDebugger() {
+ const api = useTRPC();
const { t } = useTranslation();
const [inputValue, setInputValue] = useState("");
const [bookmarkId, setBookmarkId] = useQueryState(
@@ -56,9 +58,11 @@ export default function BookmarkDebugger() {
data: debugInfo,
isLoading,
error,
- } = api.admin.getBookmarkDebugInfo.useQuery(
- { bookmarkId: bookmarkId },
- { enabled: !!bookmarkId && bookmarkId.length > 0 },
+ } = useQuery(
+ api.admin.getBookmarkDebugInfo.queryOptions(
+ { bookmarkId: bookmarkId },
+ { enabled: !!bookmarkId && bookmarkId.length > 0 },
+ ),
);
const handleLookup = () => {
@@ -67,57 +71,65 @@ export default function BookmarkDebugger() {
}
};
- const recrawlMutation = api.admin.adminRecrawlBookmark.useMutation({
- onSuccess: () => {
- toast.success(t("admin.admin_tools.action_success"), {
- description: t("admin.admin_tools.recrawl_queued"),
- });
- },
- onError: (error) => {
- toast.error(t("admin.admin_tools.action_failed"), {
- description: error.message,
- });
- },
- });
+ const recrawlMutation = useMutation(
+ api.admin.adminRecrawlBookmark.mutationOptions({
+ onSuccess: () => {
+ toast.success(t("admin.admin_tools.action_success"), {
+ description: t("admin.admin_tools.recrawl_queued"),
+ });
+ },
+ onError: (error) => {
+ toast.error(t("admin.admin_tools.action_failed"), {
+ description: error.message,
+ });
+ },
+ }),
+ );
- const reindexMutation = api.admin.adminReindexBookmark.useMutation({
- onSuccess: () => {
- toast.success(t("admin.admin_tools.action_success"), {
- description: t("admin.admin_tools.reindex_queued"),
- });
- },
- onError: (error) => {
- toast.error(t("admin.admin_tools.action_failed"), {
- description: error.message,
- });
- },
- });
+ const reindexMutation = useMutation(
+ api.admin.adminReindexBookmark.mutationOptions({
+ onSuccess: () => {
+ toast.success(t("admin.admin_tools.action_success"), {
+ description: t("admin.admin_tools.reindex_queued"),
+ });
+ },
+ onError: (error) => {
+ toast.error(t("admin.admin_tools.action_failed"), {
+ description: error.message,
+ });
+ },
+ }),
+ );
- const retagMutation = api.admin.adminRetagBookmark.useMutation({
- onSuccess: () => {
- toast.success(t("admin.admin_tools.action_success"), {
- description: t("admin.admin_tools.retag_queued"),
- });
- },
- onError: (error) => {
- toast.error(t("admin.admin_tools.action_failed"), {
- description: error.message,
- });
- },
- });
+ const retagMutation = useMutation(
+ api.admin.adminRetagBookmark.mutationOptions({
+ onSuccess: () => {
+ toast.success(t("admin.admin_tools.action_success"), {
+ description: t("admin.admin_tools.retag_queued"),
+ });
+ },
+ onError: (error) => {
+ toast.error(t("admin.admin_tools.action_failed"), {
+ description: error.message,
+ });
+ },
+ }),
+ );
- const resummarizeMutation = api.admin.adminResummarizeBookmark.useMutation({
- onSuccess: () => {
- toast.success(t("admin.admin_tools.action_success"), {
- description: t("admin.admin_tools.resummarize_queued"),
- });
- },
- onError: (error) => {
- toast.error(t("admin.admin_tools.action_failed"), {
- description: error.message,
- });
- },
- });
+ const resummarizeMutation = useMutation(
+ api.admin.adminResummarizeBookmark.mutationOptions({
+ onSuccess: () => {
+ toast.success(t("admin.admin_tools.action_success"), {
+ description: t("admin.admin_tools.resummarize_queued"),
+ });
+ },
+ onError: (error) => {
+ toast.error(t("admin.admin_tools.action_failed"), {
+ description: error.message,
+ });
+ },
+ }),
+ );
const handleRecrawl = () => {
if (bookmarkId) {
diff --git a/apps/web/components/admin/CreateInviteDialog.tsx b/apps/web/components/admin/CreateInviteDialog.tsx
index 6738adc9..c8b6be8c 100644
--- a/apps/web/components/admin/CreateInviteDialog.tsx
+++ b/apps/web/components/admin/CreateInviteDialog.tsx
@@ -20,8 +20,9 @@ import {
} from "@/components/ui/form";
import { Input } from "@/components/ui/input";
import { toast } from "@/components/ui/sonner";
-import { api } from "@/lib/trpc";
+import { useTRPC } from "@/lib/trpc";
import { zodResolver } from "@hookform/resolvers/zod";
+import { useMutation, useQueryClient } from "@tanstack/react-query";
import { TRPCClientError } from "@trpc/client";
import { useForm } from "react-hook-form";
import { z } from "zod";
@@ -37,6 +38,8 @@ interface CreateInviteDialogProps {
export default function CreateInviteDialog({
children,
}: CreateInviteDialogProps) {
+ const api = useTRPC();
+ const queryClient = useQueryClient();
const [open, setOpen] = useState(false);
const [errorMessage, setErrorMessage] = useState("");
@@ -47,25 +50,26 @@ export default function CreateInviteDialog({
},
});
- const invalidateInvitesList = api.useUtils().invites.list.invalidate;
- const createInviteMutation = api.invites.create.useMutation({
- onSuccess: () => {
- toast({
- description: "Invite sent successfully",
- });
- invalidateInvitesList();
- setOpen(false);
- form.reset();
- setErrorMessage("");
- },
- onError: (e) => {
- if (e instanceof TRPCClientError) {
- setErrorMessage(e.message);
- } else {
- setErrorMessage("Failed to send invite");
- }
- },
- });
+ const createInviteMutation = useMutation(
+ api.invites.create.mutationOptions({
+ onSuccess: () => {
+ toast({
+ description: "Invite sent successfully",
+ });
+ queryClient.invalidateQueries(api.invites.list.pathFilter());
+ setOpen(false);
+ form.reset();
+ setErrorMessage("");
+ },
+ onError: (e) => {
+ if (e instanceof TRPCClientError) {
+ setErrorMessage(e.message);
+ } else {
+ setErrorMessage("Failed to send invite");
+ }
+ },
+ }),
+ );
return (