import {View} from 'react-native' import {Trans, useLingui} from '@lingui/react/macro' import { useTrendingSettings, useTrendingSettingsApi, } from '#/state/preferences/trending' import { DEFAULT_LIMIT, useGetTrendsQuery, } from '#/state/queries/trending/useGetTrendsQuery' import {useTrendingConfig} from '#/state/service-config' import {atoms as a, useTheme} from '#/alf' import {Button, ButtonIcon} from '#/components/Button' import {DotGrid3x1_Stroke2_Corner0_Rounded as EllipsisIcon} from '#/components/icons/DotGrid' import {Trending3_Stroke2_Corner1_Rounded as TrendingIcon} from '#/components/icons/Trending' import {Link} from '#/components/Link' import * as Prompt from '#/components/Prompt' import {TrendingTopicLink} from '#/components/TrendingTopics' import {Text} from '#/components/Typography' import {useAnalytics} from '#/analytics' export function SidebarTrendingTopics() { const {enabled} = useTrendingConfig() const {trendingDisabled} = useTrendingSettings() return !enabled ? null : trendingDisabled ? null : } function Inner() { const t = useTheme() const {t: l} = useLingui() const ax = useAnalytics() const exploreTopicCount = ax.features.getValue( ax.features.TrendingExploreTopicsCountValue, DEFAULT_LIMIT, ) const trendingPrompt = Prompt.usePromptControl() const {setTrendingDisabled} = useTrendingSettingsApi() const { data: trending, error, isLoading, } = useGetTrendsQuery({ limit: DEFAULT_LIMIT, refetchOnWindowFocus: true, }) const noTopics = !isLoading && !error && !trending?.trends?.length const onConfirmHide = () => { ax.metric('trendingTopics:hide', {context: 'sidebar'}) setTrendingDisabled(true) } return error || noTopics ? null : ( <> Trending {exploreTopicCount > DEFAULT_LIMIT ? ( {({hovered, pressed}) => ( See more )} ) : null} {isLoading ? ( Array(DEFAULT_LIMIT) .fill(0) .map((_n, i) => ( {i + 1}. )) ) : !trending?.trends ? null : ( <> {trending.trends.slice(0, DEFAULT_LIMIT).map((topic, i) => ( { ax.metric('trendingTopic:click', { context: 'sidebar', recId: trending.recId, }) }}> {({hovered}) => ( {i + 1}. {topic.displayName ?? topic.topic} )} ))} )} ) }