(
client: QueryClient,
id: string,
postUpdate:
| Partial<Omit<Post, 'id'>>
| ((current: Post) => Partial<Omit<Post, 'id'>>),
)
| 682 | }; |
| 683 | |
| 684 | export 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 | |
| 720 | export const updateAdPostInCache = ( |
| 721 | postId: string, |
no test coverage detected