( postId: string, previousState: Partial<Post>, rollbackMutationHandler?: (post: Post) => Partial<Post>, )
| 721 | }; |
| 722 | |
| 723 | export const createAdPostRollbackHandler = ( |
| 724 | postId: string, |
| 725 | previousState: Partial<Post>, |
| 726 | rollbackMutationHandler?: (post: Post) => Partial<Post>, |
| 727 | ) => { |
| 728 | return (currentData: InfiniteData<Ad>): InfiniteData<Ad> => { |
| 729 | const updatedData = { ...currentData }; |
| 730 | |
| 731 | // Find and update the specific ad that contains the post |
| 732 | updatedData.pages = currentData.pages.map((page: Ad) => { |
| 733 | if (page.data?.post?.id === postId) { |
| 734 | return { |
| 735 | ...page, |
| 736 | data: { |
| 737 | ...page.data, |
| 738 | post: { |
| 739 | ...page.data.post, |
| 740 | ...(rollbackMutationHandler |
| 741 | ? rollbackMutationHandler(page.data.post) |
| 742 | : previousState), |
| 743 | }, |
| 744 | }, |
| 745 | }; |
| 746 | } |
| 747 | return page; |
| 748 | }); |
| 749 | |
| 750 | return updatedData; |
| 751 | }; |
| 752 | }; |
| 753 | |
| 754 | export const updateFeedAndAdsCache = ( |
| 755 | postId: string, |
no test coverage detected