( feedQueryKey: QueryKey, queryClient: QueryClient, pageIndex: number, manipulate: (page: AnyFeedConnection) => AnyFeedConnection, )
| 384 | }; |
| 385 | |
| 386 | export const updateCachedPage = ( |
| 387 | feedQueryKey: QueryKey, |
| 388 | queryClient: QueryClient, |
| 389 | pageIndex: number, |
| 390 | manipulate: (page: AnyFeedConnection) => AnyFeedConnection, |
| 391 | ): void => { |
| 392 | queryClient.setQueryData<InfiniteData<AnyFeedData>>( |
| 393 | feedQueryKey, |
| 394 | (currentData) => { |
| 395 | if (!currentData) { |
| 396 | return currentData; |
| 397 | } |
| 398 | |
| 399 | const currentPageData = currentData.pages[pageIndex]; |
| 400 | if (!currentPageData) { |
| 401 | return currentData; |
| 402 | } |
| 403 | |
| 404 | const { pages } = currentData; |
| 405 | const currentPage = structuredClone(currentPageData); |
| 406 | currentPage.page = manipulate( |
| 407 | currentPage.page as AnyFeedConnection, |
| 408 | ) as typeof currentPage.page; |
| 409 | const newPages = [ |
| 410 | ...pages.slice(0, pageIndex), |
| 411 | currentPage, |
| 412 | ...pages.slice(pageIndex + 1), |
| 413 | ]; |
| 414 | return { pages: newPages, pageParams: currentData.pageParams }; |
| 415 | }, |
| 416 | ); |
| 417 | }; |
| 418 | |
| 419 | export const updateCachedPagePost = |
| 420 | (feedQueryKey: QueryKey, queryClient: QueryClient) => |
no outgoing calls
no test coverage detected