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