(
client: QueryClient,
id: string,
postUpdate:
| Partial<Omit<Post, 'id'>>
| ((current: Post) => Partial<Omit<Post, 'id'>>),
)
| 636 | }; |
| 637 | |
| 638 | export const updatePostCache = ( |
| 639 | client: QueryClient, |
| 640 | id: string, |
| 641 | postUpdate: |
| 642 | | Partial<Omit<Post, 'id'>> |
| 643 | | ((current: Post) => Partial<Omit<Post, 'id'>>), |
| 644 | ): PostData | undefined => { |
| 645 | const currentPost = client.getQueryData<PostData>(getPostByIdKey(id)); |
| 646 | |
| 647 | if (!currentPost?.post) { |
| 648 | return currentPost; |
| 649 | } |
| 650 | |
| 651 | return client.setQueryData<PostData>( |
| 652 | getPostByIdKey(id), |
| 653 | (node): PostData | undefined => { |
| 654 | if (!node?.post) { |
| 655 | return node; |
| 656 | } |
| 657 | |
| 658 | const update = |
| 659 | typeof postUpdate === 'function' ? postUpdate(node.post) : postUpdate; |
| 660 | const updatedPost = { ...node.post, ...update } as Post; |
| 661 | const bookmark = updatedPost.bookmark ?? { createdAt: new Date() }; |
| 662 | |
| 663 | return { |
| 664 | post: { |
| 665 | ...updatedPost, |
| 666 | id: node.post.id, |
| 667 | bookmark: !updatedPost.bookmarked ? undefined : bookmark, |
| 668 | }, |
| 669 | }; |
| 670 | }, |
| 671 | ) as PostData | undefined; |
| 672 | }; |
| 673 | |
| 674 | export const updateAdPostInCache = ( |
| 675 | postId: string, |
no test coverage detected