( feedQueryKey: QueryKey, queryClient: QueryClient, pageIndex: number, manipulate: (page: AnyFeedConnection) => AnyFeedConnection, )
| 412 | }; |
| 413 | |
| 414 | export const updateCachedPage = ( |
| 415 | feedQueryKey: QueryKey, |
| 416 | queryClient: QueryClient, |
| 417 | pageIndex: number, |
| 418 | manipulate: (page: AnyFeedConnection) => AnyFeedConnection, |
| 419 | ): void => { |
| 420 | queryClient.setQueryData<InfiniteData<AnyFeedData>>( |
| 421 | feedQueryKey, |
| 422 | (currentData) => { |
| 423 | if (!currentData) { |
| 424 | return currentData; |
| 425 | } |
| 426 | |
| 427 | const currentPageData = currentData.pages[pageIndex]; |
| 428 | if (!currentPageData) { |
| 429 | return currentData; |
| 430 | } |
| 431 | |
| 432 | const { pages } = currentData; |
| 433 | const currentPage = structuredClone(currentPageData); |
| 434 | currentPage.page = manipulate( |
| 435 | currentPage.page as AnyFeedConnection, |
| 436 | ) as typeof currentPage.page; |
| 437 | const newPages = [ |
| 438 | ...pages.slice(0, pageIndex), |
| 439 | currentPage, |
| 440 | ...pages.slice(pageIndex + 1), |
| 441 | ]; |
| 442 | return { pages: newPages, pageParams: currentData.pageParams }; |
| 443 | }, |
| 444 | ); |
| 445 | }; |
| 446 | |
| 447 | export const updateCachedPagePost = |
| 448 | (feedQueryKey: QueryKey, queryClient: QueryClient) => |
no outgoing calls
no test coverage detected