Skip to content

Commit

Permalink
Fix: Correctly invalidate the bookmark cache when it's favourited
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamedBassem committed Mar 4, 2024
1 parent 7e2afd2 commit 2ab8bf0
Showing 1 changed file with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,29 @@ 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",
title: "Something went wrong",
description: "There was a problem with your request.",
});
};
const onSettled = () => {
invalidateBookmarksCache();
};
const deleteBookmarkMutator = api.bookmarks.deleteBookmark.useMutation({
onSuccess: () => {
toast({
description: "The bookmark has been deleted!",
});
},
onError,
onSettled,
onSettled: () => {
invalidateAllBookmarksCache();
},
});

const updateBookmarkMutator = api.bookmarks.updateBookmark.useMutation({
Expand All @@ -67,7 +69,9 @@ export default function BookmarkOptions({ bookmark }: { bookmark: ZBookmark }) {
});
},
onError,
onSettled,
onSettled: () => {
invalidateBookmarkCache({ bookmarkId: bookmark.id });
},
});

const crawlBookmarkMutator = api.bookmarks.recrawlBookmark.useMutation({
Expand All @@ -77,7 +81,9 @@ export default function BookmarkOptions({ bookmark }: { bookmark: ZBookmark }) {
});
},
onError,
onSettled,
onSettled: () => {
invalidateBookmarkCache({ bookmarkId: bookmark.id });
},
});

return (
Expand Down

0 comments on commit 2ab8bf0

Please sign in to comment.