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

Function updateCachedPage

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

Source from the content-addressed store, hash-verified

384};
385
386export 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
419export const updateCachedPagePost =
420 (feedQueryKey: QueryKey, queryClient: QueryClient) =>

Callers 2

updateCachedPagePostFunction · 0.85
removeCachedPagePostFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected