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

Function updatePostCache

packages/shared/src/lib/query.ts:637–671  ·  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

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