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

Function useFeed

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

Source from the content-addressed store, hash-verified

276}
277
278export default function useFeed<T>(
279 feedQueryKey: QueryKey,
280 pageSize: number,
281 adTemplate: FeedAdTemplate,
282 placeholdersPerPage: number,
283 params: UseFeedOptionalParams<T> = {},
284): FeedReturnType {
285 const router = useRouter();
286 const { logEvent } = useLogContext();
287 const {
288 query,
289 variables,
290 options = {},
291 settings,
292 onEmptyFeed,
293 isBriefBannerEligible = false,
294 engagementStripEligible = false,
295 firstSlotOffset = 0,
296 disableTopHero = false,
297 isHorizontal = false,
298 excludePinnedPosts = false,
299 } = params;
300 const { numCards: numCardsBySpaciness } = useContext(FeedContext);
301 const numCards = numCardsBySpaciness.eco;
302 const { user, tokenRefreshed } = useContext(AuthContext);
303 const { isPlus } = usePlusSubscription();
304 const queryClient = useQueryClient();
305 const isTabletViewport = useViewSize(ViewSize.Tablet);
306 const isMobileViewport = !isTabletViewport;
307 const { isListMode, shouldUseListFeedLayout } = useFeedLayout();
308 const useList = isListMode && numCards > 1;
309 const isListContext = useList || shouldUseListFeedLayout;
310 const virtualizedNumCards = useList ? 1 : numCards;
311 const canRenderHighlightCards =
312 !isMobileViewport &&
313 !isListContext &&
314 !isHorizontal &&
315 virtualizedNumCards > 1 &&
316 HERO_ELIGIBLE_FEEDS.has(settings?.feedName as AllFeedPages);
317 const { value: isHighlightCardsOptedOut } = useSettingsBooleanFlag(
318 'highlightCardsOptOut',
319 );
320 const { fetchTranslations } = useTranslation({
321 queryKey: feedQueryKey,
322 queryType: 'feed',
323 });
324 const isFeedPreview = feedQueryKey?.[0] === RequestKey.FeedPreview;
325 const avoidRetry =
326 params?.settings?.feedName === SharedFeedPage.Custom && !isPlus;
327 const feedQuery = useInfiniteQuery<
328 FeedItemData,
329 ClientError,
330 InfiniteData<FeedItemData, string>,
331 QueryKey,
332 string
333 >({
334 queryKey: feedQueryKey,
335 queryFn: async ({ pageParam }) => {

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
searchResultsLogEventFunction · 0.90
getFeedApiItemPostFunction · 0.90
getNextPageParamFunction · 0.90
isHeroEligiblePostFunction · 0.90
useConditionalFeatureFunction · 0.90

Tested by

no test coverage detected