mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at patch-version 116 lines 3.8 kB view raw
1import React from 'react' 2import {View} from 'react-native' 3import {msg, Trans} from '@lingui/macro' 4import {useLingui} from '@lingui/react' 5 6import {logEvent} from '#/lib/statsig/statsig' 7import { 8 useTrendingSettings, 9 useTrendingSettingsApi, 10} from '#/state/preferences/trending' 11import {useTrendingTopics} from '#/state/queries/trending/useTrendingTopics' 12import {useTrendingConfig} from '#/state/trending-config' 13import {atoms as a, useTheme} from '#/alf' 14import {Button, ButtonIcon} from '#/components/Button' 15import {Divider} from '#/components/Divider' 16import {TimesLarge_Stroke2_Corner0_Rounded as X} from '#/components/icons/Times' 17import {Trending2_Stroke2_Corner2_Rounded as Graph} from '#/components/icons/Trending2' 18import * as Prompt from '#/components/Prompt' 19import { 20 TrendingTopic, 21 TrendingTopicLink, 22 TrendingTopicSkeleton, 23} from '#/components/TrendingTopics' 24import {Text} from '#/components/Typography' 25 26const TRENDING_LIMIT = 6 27 28export function SidebarTrendingTopics() { 29 const {enabled} = useTrendingConfig() 30 const {trendingDisabled} = useTrendingSettings() 31 return !enabled ? null : trendingDisabled ? null : <Inner /> 32} 33 34function Inner() { 35 const t = useTheme() 36 const {_} = useLingui() 37 const trendingPrompt = Prompt.usePromptControl() 38 const {setTrendingDisabled} = useTrendingSettingsApi() 39 const {data: trending, error, isLoading} = useTrendingTopics() 40 const noTopics = !isLoading && !error && !trending?.topics?.length 41 42 const onConfirmHide = React.useCallback(() => { 43 logEvent('trendingTopics:hide', {context: 'sidebar'}) 44 setTrendingDisabled(true) 45 }, [setTrendingDisabled]) 46 47 return error || noTopics ? null : ( 48 <> 49 <View style={[a.gap_sm, {paddingBottom: 2}]}> 50 <View style={[a.flex_row, a.align_center, a.gap_xs]}> 51 <Graph size="sm" /> 52 <Text 53 style={[ 54 a.flex_1, 55 a.text_sm, 56 a.font_bold, 57 t.atoms.text_contrast_medium, 58 ]}> 59 <Trans>Trending</Trans> 60 </Text> 61 <Button 62 label={_(msg`Hide trending topics`)} 63 size="tiny" 64 variant="ghost" 65 color="secondary" 66 shape="round" 67 onPress={() => trendingPrompt.open()}> 68 <ButtonIcon icon={X} /> 69 </Button> 70 </View> 71 72 <View style={[a.flex_row, a.flex_wrap, {gap: '6px 4px'}]}> 73 {isLoading ? ( 74 Array(TRENDING_LIMIT) 75 .fill(0) 76 .map((_n, i) => ( 77 <TrendingTopicSkeleton key={i} size="small" index={i} /> 78 )) 79 ) : !trending?.topics ? null : ( 80 <> 81 {trending.topics.slice(0, TRENDING_LIMIT).map(topic => ( 82 <TrendingTopicLink 83 key={topic.link} 84 topic={topic} 85 onPress={() => { 86 logEvent('trendingTopic:click', {context: 'sidebar'}) 87 }}> 88 {({hovered}) => ( 89 <TrendingTopic 90 size="small" 91 topic={topic} 92 style={[ 93 hovered && [ 94 t.atoms.border_contrast_high, 95 t.atoms.bg_contrast_25, 96 ], 97 ]} 98 /> 99 )} 100 </TrendingTopicLink> 101 ))} 102 </> 103 )} 104 </View> 105 </View> 106 <Prompt.Basic 107 control={trendingPrompt} 108 title={_(msg`Hide trending topics?`)} 109 description={_(msg`You can update this later from your settings.`)} 110 confirmButtonCta={_(msg`Hide`)} 111 onConfirm={onConfirmHide} 112 /> 113 <Divider /> 114 </> 115 ) 116}