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

Function updatePostCache

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

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