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

Function updatePostCache

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

660};
661
662export const updatePostCache = (
663 client: QueryClient,
664 id: string,
665 postUpdate:
666 | Partial<Omit<Post, 'id'>>
667 | ((current: Post) => Partial<Omit<Post, 'id'>>),
668): PostData | undefined => {
669 const currentPost = client.getQueryData<PostData>(getPostByIdKey(id));
670
671 if (!currentPost?.post) {
672 return currentPost;
673 }
674
675 return client.setQueryData<PostData>(
676 getPostByIdKey(id),
677 (node): PostData | undefined => {
678 if (!node?.post) {
679 return node;
680 }
681
682 const update =
683 typeof postUpdate === 'function' ? postUpdate(node.post) : postUpdate;
684 const updatedPost = { ...node.post, ...update } as Post;
685 const bookmark = updatedPost.bookmark ?? { createdAt: new Date() };
686
687 return {
688 post: {
689 ...updatedPost,
690 id: node.post.id,
691 bookmark: !updatedPost.bookmarked ? undefined : bookmark,
692 },
693 };
694 },
695 ) as PostData | undefined;
696};
697
698export const updateAdPostInCache = (
699 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