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