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

Function updateFeedAndAdsCache

packages/shared/src/lib/query.ts:778–824  ·  view source on GitHub ↗
(
  postId: string,
  feedQueryKey: QueryKey,
  queryClient: QueryClient,
  update: Partial<Post>,
)

Source from the content-addressed store, hash-verified

776};
777
778export const updateFeedAndAdsCache = (
779 postId: string,
780 feedQueryKey: QueryKey,
781 queryClient: QueryClient,
782 update: Partial<Post>,
783): void => {
784 // Update the main feed cache
785 const updateFeedPost = updateCachedPagePost(feedQueryKey, queryClient);
786 const feedData =
787 queryClient.getQueryData<InfiniteData<AnyFeedData>>(feedQueryKey);
788
789 if (feedData) {
790 const { pageIndex, index } = findIndexOfPostInData(feedData, postId, true);
791 if (index > -1) {
792 const currentPost = getFeedApiItemPost(
793 feedData.pages[pageIndex].page.edges[index].node,
794 );
795
796 if (!currentPost) {
797 throw new Error(
798 `Missing post-backed feed item at page ${pageIndex} index ${index}`,
799 );
800 }
801
802 updateFeedPost(pageIndex, index, {
803 ...currentPost,
804 ...update,
805 });
806 }
807 }
808
809 // Update the ads cache if the post exists there
810 const adsQueryKey = [RequestKey.Ads, ...feedQueryKey];
811 const adsData = queryClient.getQueryData<InfiniteData<Ad>>(adsQueryKey);
812
813 if (adsData) {
814 const existingAdPost = adsData.pages.find(
815 (page) => page.data?.post?.id === postId,
816 )?.data?.post;
817
818 if (existingAdPost) {
819 queryClient.setQueryData(adsQueryKey, (currentData: InfiniteData<Ad>) => {
820 return updateAdPostInCache(postId, currentData, update);
821 });
822 }
823 }
824};

Callers 3

useOnPostClickFunction · 0.90
usePostFeedbackFunction · 0.90
useFeedOnPostClickFunction · 0.90

Calls 4

getFeedApiItemPostFunction · 0.90
updateCachedPagePostFunction · 0.85
findIndexOfPostInDataFunction · 0.85
updateAdPostInCacheFunction · 0.85

Tested by

no test coverage detected