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

Function updatePostCache

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

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