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

Function updatePostCache

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

675};
676
677export const updatePostCache = (
678 client: QueryClient,
679 id: string,
680 postUpdate:
681 | Partial<Omit<Post, 'id'>>
682 | ((current: Post) => Partial<Omit<Post, 'id'>>),
683): PostData | undefined => {
684 const currentPost = client.getQueryData<PostData>(getPostByIdKey(id));
685
686 if (!currentPost?.post) {
687 return currentPost;
688 }
689
690 return client.setQueryData<PostData>(
691 getPostByIdKey(id),
692 (node): PostData | undefined => {
693 if (!node?.post) {
694 return node;
695 }
696
697 const update =
698 typeof postUpdate === 'function' ? postUpdate(node.post) : postUpdate;
699 const updatedPost = { ...node.post, ...update } as Post;
700 const bookmark = updatedPost.bookmark ?? { createdAt: new Date() };
701
702 return {
703 post: {
704 ...updatedPost,
705 id: node.post.id,
706 bookmark: !updatedPost.bookmarked ? undefined : bookmark,
707 },
708 };
709 },
710 ) as PostData | undefined;
711};
712
713export const updateAdPostInCache = (
714 postId: string,

Callers 15

PostActionsV1Function · 0.90
PostActionsFunction · 0.90
BoostPostModalFunction · 0.90
BoostedViewModalFunction · 0.90
defaultOnMutateFunction · 0.90
usePollFunction · 0.90
usePostContentFunction · 0.90
usePostFeedbackFunction · 0.90
removeCachedCommentFunction · 0.90
onUpdateCacheFunction · 0.90
useTranslationFunction · 0.90
useFeedBookmarkPostFunction · 0.90

Calls 1

getPostByIdKeyFunction · 0.85

Tested by

no test coverage detected