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

Function updateCachedPage

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

Source from the content-addressed store, hash-verified

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

Callers 2

updateCachedPagePostFunction · 0.85
removeCachedPagePostFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected