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

Function updatePostCache

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

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