( postId: string, previousState: Partial<Post>, rollbackMutationHandler?: (post: Post) => Partial<Post>, )
| 734 | }; |
| 735 | |
| 736 | export const createAdPostRollbackHandler = ( |
| 737 | postId: string, |
| 738 | previousState: Partial<Post>, |
| 739 | rollbackMutationHandler?: (post: Post) => Partial<Post>, |
| 740 | ) => { |
| 741 | return (currentData: InfiniteData<Ad>): InfiniteData<Ad> => { |
| 742 | const updatedData = { ...currentData }; |
| 743 | |
| 744 | // Find and update the specific ad that contains the post |
| 745 | updatedData.pages = currentData.pages.map((page: Ad) => { |
| 746 | if (page.data?.post?.id === postId) { |
| 747 | return { |
| 748 | ...page, |
| 749 | data: { |
| 750 | ...page.data, |
| 751 | post: { |
| 752 | ...page.data.post, |
| 753 | ...(rollbackMutationHandler |
| 754 | ? rollbackMutationHandler(page.data.post) |
| 755 | : previousState), |
| 756 | }, |
| 757 | }, |
| 758 | }; |
| 759 | } |
| 760 | return page; |
| 761 | }); |
| 762 | |
| 763 | return updatedData; |
| 764 | }; |
| 765 | }; |
| 766 | |
| 767 | export const updateFeedAndAdsCache = ( |
| 768 | postId: string, |
no test coverage detected