(
feedQueryKey: QueryKey,
pageSize: number,
adTemplate: FeedAdTemplate,
placeholdersPerPage: number,
params: UseFeedOptionalParams<T> = {},
)
| 276 | } |
| 277 | |
| 278 | export 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 }) => { |
no test coverage detected