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