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

Function updatePostCache

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

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