( postId: string, previousState: Partial<Post>, rollbackMutationHandler?: (post: Post) => Partial<Post>, )
| 699 | }; |
| 700 | |
| 701 | export const createAdPostRollbackHandler = ( |
| 702 | postId: string, |
| 703 | previousState: Partial<Post>, |
| 704 | rollbackMutationHandler?: (post: Post) => Partial<Post>, |
| 705 | ) => { |
| 706 | return (currentData: InfiniteData<Ad>): InfiniteData<Ad> => { |
| 707 | const updatedData = { ...currentData }; |
| 708 | |
| 709 | // Find and update the specific ad that contains the post |
| 710 | updatedData.pages = currentData.pages.map((page: Ad) => { |
| 711 | if (page.data?.post?.id === postId) { |
| 712 | return { |
| 713 | ...page, |
| 714 | data: { |
| 715 | ...page.data, |
| 716 | post: { |
| 717 | ...page.data.post, |
| 718 | ...(rollbackMutationHandler |
| 719 | ? rollbackMutationHandler(page.data.post) |
| 720 | : previousState), |
| 721 | }, |
| 722 | }, |
| 723 | }; |
| 724 | } |
| 725 | return page; |
| 726 | }); |
| 727 | |
| 728 | return updatedData; |
| 729 | }; |
| 730 | }; |
| 731 | |
| 732 | export const updateFeedAndAdsCache = ( |
| 733 | postId: string, |
no test coverage detected