MCPcopy Create free account
hub / github.com/dailydotdev/apps / updateCachedPage

Function updateCachedPage

packages/shared/src/lib/query.ts:402–433  ·  view source on GitHub ↗
(
  feedQueryKey: QueryKey,
  queryClient: QueryClient,
  pageIndex: number,
  manipulate: (page: AnyFeedConnection) => AnyFeedConnection,
)

Source from the content-addressed store, hash-verified

400};
401
402export 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
435export const updateCachedPagePost =
436 (feedQueryKey: QueryKey, queryClient: QueryClient) =>

Callers 2

updateCachedPagePostFunction · 0.85
removeCachedPagePostFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected