From 2ab8bf09fdaf7df11346ff2e3101f27531deba10 Mon Sep 17 00:00:00 2001 From: MohamedBassem Date: Mon, 4 Mar 2024 22:36:38 +0000 Subject: [PATCH] Fix: Correctly invalidate the bookmark cache when it's favourited --- .../bookmarks/components/BookmarkOptions.tsx | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/packages/web/app/dashboard/bookmarks/components/BookmarkOptions.tsx b/packages/web/app/dashboard/bookmarks/components/BookmarkOptions.tsx index 62a0a625..64411e68 100644 --- a/packages/web/app/dashboard/bookmarks/components/BookmarkOptions.tsx +++ b/packages/web/app/dashboard/bookmarks/components/BookmarkOptions.tsx @@ -37,9 +37,12 @@ export default function BookmarkOptions({ bookmark }: { bookmark: ZBookmark }) { const [isTextEditorOpen, setTextEditorOpen] = useState(false); - const invalidateBookmarksCache = + const invalidateAllBookmarksCache = api.useUtils().bookmarks.getBookmarks.invalidate; + const invalidateBookmarkCache = + api.useUtils().bookmarks.getBookmark.invalidate; + const onError = () => { toast({ variant: "destructive", @@ -47,9 +50,6 @@ export default function BookmarkOptions({ bookmark }: { bookmark: ZBookmark }) { description: "There was a problem with your request.", }); }; - const onSettled = () => { - invalidateBookmarksCache(); - }; const deleteBookmarkMutator = api.bookmarks.deleteBookmark.useMutation({ onSuccess: () => { toast({ @@ -57,7 +57,9 @@ export default function BookmarkOptions({ bookmark }: { bookmark: ZBookmark }) { }); }, onError, - onSettled, + onSettled: () => { + invalidateAllBookmarksCache(); + }, }); const updateBookmarkMutator = api.bookmarks.updateBookmark.useMutation({ @@ -67,7 +69,9 @@ export default function BookmarkOptions({ bookmark }: { bookmark: ZBookmark }) { }); }, onError, - onSettled, + onSettled: () => { + invalidateBookmarkCache({ bookmarkId: bookmark.id }); + }, }); const crawlBookmarkMutator = api.bookmarks.recrawlBookmark.useMutation({ @@ -77,7 +81,9 @@ export default function BookmarkOptions({ bookmark }: { bookmark: ZBookmark }) { }); }, onError, - onSettled, + onSettled: () => { + invalidateBookmarkCache({ bookmarkId: bookmark.id }); + }, }); return (