( feedQueryKey: QueryKey, queryClient: QueryClient, pageIndex: number, manipulate: (page: AnyFeedConnection) => AnyFeedConnection, )
| 400 | }; |
| 401 | |
| 402 | export const updateCachedPage = ( |
| 403 | feedQueryKey: QueryKey, |
| 404 | queryClient: QueryClient, |
| 405 | pageIndex: number, |
| 406 | manipulate: (page: AnyFeedConnection) => AnyFeedConnection, |
| 407 | ): void => { |
| 408 | queryClient.setQueryData<InfiniteData<AnyFeedData>>( |
| 409 | feedQueryKey, |
| 410 | (currentData) => { |
| 411 | if (!currentData) { |
| 412 | return currentData; |
| 413 | } |
| 414 | |
| 415 | const currentPageData = currentData.pages[pageIndex]; |
| 416 | if (!currentPageData) { |
| 417 | return currentData; |
| 418 | } |
| 419 | |
| 420 | const { pages } = currentData; |
| 421 | const currentPage = structuredClone(currentPageData); |
| 422 | currentPage.page = manipulate( |
| 423 | currentPage.page as AnyFeedConnection, |
| 424 | ) as typeof currentPage.page; |
| 425 | const newPages = [ |
| 426 | ...pages.slice(0, pageIndex), |
| 427 | currentPage, |
| 428 | ...pages.slice(pageIndex + 1), |
| 429 | ]; |
| 430 | return { pages: newPages, pageParams: currentData.pageParams }; |
| 431 | }, |
| 432 | ); |
| 433 | }; |
| 434 | |
| 435 | export const updateCachedPagePost = |
| 436 | (feedQueryKey: QueryKey, queryClient: QueryClient) => |
no outgoing calls
no test coverage detected