MCPcopy Create free account
hub / github.com/dailydotdev/apps / defaultOnMutate

Function defaultOnMutate

packages/shared/src/hooks/useBookmarkPost.ts:102–137  ·  view source on GitHub ↗
({
    id,
  })

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 3

getPostByIdKeyFunction · 0.90
updatePostCacheFunction · 0.90

Tested by

no test coverage detected