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