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

Function updatePostCache

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

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

Callers 15

useFeedHeroPostActionsFunction · 0.90
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

Calls 1

getPostByIdKeyFunction · 0.85

Tested by

no test coverage detected