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