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

Function updateCachedPage

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

Source from the content-addressed store, hash-verified

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

Callers 2

updateCachedPagePostFunction · 0.85
removeCachedPagePostFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected