({
id,
})
| 100 | const { logOpts } = useActiveFeedContext(); |
| 101 | |
| 102 | const defaultOnMutate: NonNullable<UseBookmarkPostProps['onMutate']> = ({ |
| 103 | id, |
| 104 | }) => { |
| 105 | if (!id) { |
| 106 | return undefined; |
| 107 | } |
| 108 | |
| 109 | const previousPost = client.getQueryData<PostData>( |
| 110 | getPostByIdKey(id), |
| 111 | )?.post; |
| 112 | |
| 113 | updatePostCache(client, id, (post) => ({ |
| 114 | bookmarked: !post.bookmarked, |
| 115 | analytics: post.analytics |
| 116 | ? { |
| 117 | ...post.analytics, |
| 118 | bookmarks: getOptimisticBookmarkCount( |
| 119 | post.analytics.bookmarks, |
| 120 | post.bookmarked, |
| 121 | ), |
| 122 | } |
| 123 | : post.analytics, |
| 124 | })); |
| 125 | |
| 126 | return () => { |
| 127 | if (!previousPost) { |
| 128 | return; |
| 129 | } |
| 130 | |
| 131 | updatePostCache(client, id, () => ({ |
| 132 | bookmarked: previousPost.bookmarked, |
| 133 | bookmark: previousPost.bookmark, |
| 134 | analytics: previousPost.analytics, |
| 135 | })); |
| 136 | }; |
| 137 | }; |
| 138 | |
| 139 | const { mutateAsync: bookmarkPost } = useMutation({ |
| 140 | mutationKey: mutationKey |
nothing calls this directly
no test coverage detected