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