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

Function useFeed

packages/shared/src/hooks/useFeed.ts:264–873  ·  view source on GitHub ↗
(
  feedQueryKey: QueryKey,
  pageSize: number,
  adTemplate: FeedAdTemplate,
  placeholdersPerPage: number,
  params: UseFeedOptionalParams<T> = {},
)

Source from the content-addressed store, hash-verified

262}
263
264export default function useFeed<T>(
265 feedQueryKey: QueryKey,
266 pageSize: number,
267 adTemplate: FeedAdTemplate,
268 placeholdersPerPage: number,
269 params: UseFeedOptionalParams<T> = {},
270): FeedReturnType {
271 const router = useRouter();
272 const { logEvent } = useLogContext();
273 const {
274 query,
275 variables,
276 options = {},
277 settings,
278 onEmptyFeed,
279 isBriefBannerEligible = false,
280 engagementStripEligible = false,
281 firstSlotOffset = 0,
282 disableTopHero = false,
283 } = params;
284 const { numCards: numCardsBySpaciness } = useContext(FeedContext);
285 const numCards = numCardsBySpaciness.eco;
286 const { user, tokenRefreshed } = useContext(AuthContext);
287 const { isPlus } = usePlusSubscription();
288 const queryClient = useQueryClient();
289 const isTabletViewport = useViewSize(ViewSize.Tablet);
290 const isMobileViewport = !isTabletViewport;
291 const { isListMode, shouldUseListFeedLayout } = useFeedLayout();
292 const useList = isListMode && numCards > 1;
293 const isListContext = useList || shouldUseListFeedLayout;
294 const virtualizedNumCards = useList ? 1 : numCards;
295 const canRenderHighlightCards =
296 !isMobileViewport &&
297 !isListContext &&
298 virtualizedNumCards > 1 &&
299 HERO_ELIGIBLE_FEEDS.has(settings?.feedName as AllFeedPages);
300 const { value: isHighlightCardsOptedOut } = useSettingsBooleanFlag(
301 'highlightCardsOptOut',
302 );
303 // Track if we're currently resetting due to stale cursor to prevent infinite loops
304 const isResettingRef = useRef(false);
305 const { fetchTranslations } = useTranslation({
306 queryKey: feedQueryKey,
307 queryType: 'feed',
308 });
309 const isFeedPreview = feedQueryKey?.[0] === RequestKey.FeedPreview;
310 const avoidRetry =
311 params?.settings?.feedName === SharedFeedPage.Custom && !isPlus;
312 const feedQuery = useInfiniteQuery<
313 FeedItemData,
314 ClientError,
315 InfiniteData<FeedItemData, string>,
316 QueryKey,
317 string
318 >({
319 queryKey: feedQueryKey,
320 queryFn: async ({ pageParam }) => {
321 if (!query) {

Callers 2

FeedFunction · 0.85
PageFunction · 0.85

Calls 15

useLogContextFunction · 0.90
usePlusSubscriptionFunction · 0.90
useViewSizeFunction · 0.90
useFeedLayoutFunction · 0.90
useSettingsBooleanFlagFunction · 0.90
useTranslationFunction · 0.90
normalizeFeedPageFunction · 0.90
getFeedApiItemPostFunction · 0.90
getNextPageParamFunction · 0.90
isHeroEligiblePostFunction · 0.90
useConditionalFeatureFunction · 0.90

Tested by

no test coverage detected