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