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

Function updateCachedPage

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

Source from the content-addressed store, hash-verified

413};
414
415export const updateCachedPage = (
416 feedQueryKey: QueryKey,
417 queryClient: QueryClient,
418 pageIndex: number,
419 manipulate: (page: AnyFeedConnection) => AnyFeedConnection,
420): void => {
421 queryClient.setQueryData<InfiniteData<AnyFeedData>>(
422 feedQueryKey,
423 (currentData) => {
424 if (!currentData) {
425 return currentData;
426 }
427
428 const currentPageData = currentData.pages[pageIndex];
429 if (!currentPageData) {
430 return currentData;
431 }
432
433 const { pages } = currentData;
434 const currentPage = structuredClone(currentPageData);
435 currentPage.page = manipulate(
436 currentPage.page as AnyFeedConnection,
437 ) as typeof currentPage.page;
438 const newPages = [
439 ...pages.slice(0, pageIndex),
440 currentPage,
441 ...pages.slice(pageIndex + 1),
442 ];
443 return { pages: newPages, pageParams: currentData.pageParams };
444 },
445 );
446};
447
448export const updateCachedPagePost =
449 (feedQueryKey: QueryKey, queryClient: QueryClient) =>

Callers 2

updateCachedPagePostFunction · 0.85
removeCachedPagePostFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected