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

Function updatePostCache

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

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