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