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

Function updateCachedPage

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

Source from the content-addressed store, hash-verified

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

Callers 2

updateCachedPagePostFunction · 0.85
removeCachedPagePostFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected