From 79d61be7e15dc5d23fb687a5f71e0097088a99ac Mon Sep 17 00:00:00 2001
From: MohamedBassem <me@mbassem.com>
Date: Sun, 7 Apr 2024 18:30:00 +0100
Subject: feature: Extract hook logic into separate package and add a new
 action bar in bookmark preview

---
 apps/mobile/components/bookmarks/BookmarkCard.tsx | 25 ++++++++---------------
 1 file changed, 9 insertions(+), 16 deletions(-)

(limited to 'apps/mobile/components/bookmarks/BookmarkCard.tsx')

diff --git a/apps/mobile/components/bookmarks/BookmarkCard.tsx b/apps/mobile/components/bookmarks/BookmarkCard.tsx
index 89ce7924..d4fbcb58 100644
--- a/apps/mobile/components/bookmarks/BookmarkCard.tsx
+++ b/apps/mobile/components/bookmarks/BookmarkCard.tsx
@@ -17,6 +17,10 @@ import { MenuView } from "@react-native-menu/menu";
 import { Ellipsis, Star } from "lucide-react-native";
 
 import type { ZBookmark } from "@hoarder/trpc/types/bookmarks";
+import {
+  useDeleteBookmark,
+  useUpdateBookmark,
+} from "@hoarder/shared-react/hooks/bookmarks";
 
 import { Divider } from "../ui/Divider";
 import { Skeleton } from "../ui/Skeleton";
@@ -45,7 +49,6 @@ export function isBookmarkStillLoading(bookmark: ZBookmark) {
 
 function ActionBar({ bookmark }: { bookmark: ZBookmark }) {
   const { toast } = useToast();
-  const apiUtils = api.useUtils();
 
   const onError = () => {
     toast({
@@ -56,37 +59,27 @@ function ActionBar({ bookmark }: { bookmark: ZBookmark }) {
   };
 
   const { mutate: deleteBookmark, isPending: isDeletionPending } =
-    api.bookmarks.deleteBookmark.useMutation({
+    useDeleteBookmark({
       onSuccess: () => {
         toast({
           message: "The bookmark has been deleted!",
           showProgress: false,
         });
-        apiUtils.bookmarks.getBookmarks.invalidate();
-        apiUtils.bookmarks.searchBookmarks.invalidate();
       },
       onError,
     });
 
-  const { mutate: favouriteBookmark, variables } =
-    api.bookmarks.updateBookmark.useMutation({
-      onSuccess: () => {
-        apiUtils.bookmarks.getBookmarks.invalidate();
-        apiUtils.bookmarks.getBookmark.invalidate({ bookmarkId: bookmark.id });
-      },
-      onError,
-    });
+  const { mutate: favouriteBookmark, variables } = useUpdateBookmark({
+    onError,
+  });
 
   const { mutate: archiveBookmark, isPending: isArchivePending } =
-    api.bookmarks.updateBookmark.useMutation({
+    useUpdateBookmark({
       onSuccess: (resp) => {
         toast({
           message: `The bookmark has been ${resp.archived ? "archived" : "un-archived"}!`,
           showProgress: false,
         });
-        apiUtils.bookmarks.getBookmarks.invalidate();
-        apiUtils.bookmarks.getBookmark.invalidate({ bookmarkId: bookmark.id });
-        apiUtils.bookmarks.searchBookmarks.invalidate();
       },
       onError,
     });
-- 
cgit v1.2.3-70-g09d2

