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

Function updatePostCache

packages/shared/src/lib/query.ts:638–672  ·  view source on GitHub ↗
(
  client: QueryClient,
  id: string,
  postUpdate:
    | Partial<Omit<Post, 'id'>>
    | ((current: Post) => Partial<Omit<Post, 'id'>>),
)

Source from the content-addressed store, hash-verified

636};
637
638export const updatePostCache = (
639 client: QueryClient,
640 id: string,
641 postUpdate:
642 | Partial<Omit<Post, 'id'>>
643 | ((current: Post) => Partial<Omit<Post, 'id'>>),
644): PostData | undefined => {
645 const currentPost = client.getQueryData<PostData>(getPostByIdKey(id));
646
647 if (!currentPost?.post) {
648 return currentPost;
649 }
650
651 return client.setQueryData<PostData>(
652 getPostByIdKey(id),
653 (node): PostData | undefined => {
654 if (!node?.post) {
655 return node;
656 }
657
658 const update =
659 typeof postUpdate === 'function' ? postUpdate(node.post) : postUpdate;
660 const updatedPost = { ...node.post, ...update } as Post;
661 const bookmark = updatedPost.bookmark ?? { createdAt: new Date() };
662
663 return {
664 post: {
665 ...updatedPost,
666 id: node.post.id,
667 bookmark: !updatedPost.bookmarked ? undefined : bookmark,
668 },
669 };
670 },
671 ) as PostData | undefined;
672};
673
674export const updateAdPostInCache = (
675 postId: string,

Callers 15

BookmarkFeedLayoutFunction · 0.90
useFeedHeroPostActionsFunction · 0.90
PostActionsV1Function · 0.90
PostActionsFunction · 0.90
BoostPostModalFunction · 0.90
clearBoostedFlagFunction · 0.90
defaultOnMutateFunction · 0.90
usePollFunction · 0.90
usePostContentFunction · 0.90
usePostFeedbackFunction · 0.90
removeCachedCommentFunction · 0.90

Calls 1

getPostByIdKeyFunction · 0.85

Tested by

no test coverage detected