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

Function updateFeedAndAdsCache

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

Source from the content-addressed store, hash-verified

759};
760
761export const updateFeedAndAdsCache = (
762 postId: string,
763 feedQueryKey: QueryKey,
764 queryClient: QueryClient,
765 update: Partial<Post>,
766): void => {
767 // Update the main feed cache
768 const updateFeedPost = updateCachedPagePost(feedQueryKey, queryClient);
769 const feedData =
770 queryClient.getQueryData<InfiniteData<AnyFeedData>>(feedQueryKey);
771
772 if (feedData) {
773 const { pageIndex, index } = findIndexOfPostInData(feedData, postId, true);
774 if (index > -1) {
775 const currentPost = getFeedApiItemPost(
776 feedData.pages[pageIndex].page.edges[index].node,
777 );
778
779 if (!currentPost) {
780 throw new Error(
781 `Missing post-backed feed item at page ${pageIndex} index ${index}`,
782 );
783 }
784
785 updateFeedPost(pageIndex, index, {
786 ...currentPost,
787 ...update,
788 });
789 }
790 }
791
792 // Update the ads cache if the post exists there
793 const adsQueryKey = [RequestKey.Ads, ...feedQueryKey];
794 const adsData = queryClient.getQueryData<InfiniteData<Ad>>(adsQueryKey);
795
796 if (adsData) {
797 const existingAdPost = adsData.pages.find(
798 (page) => page.data?.post?.id === postId,
799 )?.data?.post;
800
801 if (existingAdPost) {
802 queryClient.setQueryData(adsQueryKey, (currentData: InfiniteData<Ad>) => {
803 return updateAdPostInCache(postId, currentData, update);
804 });
805 }
806 }
807};

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