Something went wrong. Try again.
Mirror — see github.com/blacksky-algorithms/blacksky.community
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979import {type ComponentProps, type JSX, memo, useCallback} from 'react'import { Linking, Pressable, ScrollView, TouchableOpacity, View,} from 'react-native'import {useSafeAreaInsets} from 'react-native-safe-area-context'import {plural} from '@lingui/core/macro'import {Trans, useLingui} from '@lingui/react/macro'import {type NavigationState} from '@react-navigation/native'import {StackActions, useNavigation} from '@react-navigation/native'
import {useBrand} from '#/lib/community/BrandContext'import { FEEDBACK_FORM_URL, HELP_DESK_URL, UNREAD_NOTIFICATION_CAP,} from '#/lib/constants'import {type PressableScale} from '#/lib/custom-animations/PressableScale'import {useNavigationTabState} from '#/lib/hooks/useNavigationTabState'import {getTabState, TabState} from '#/lib/routes/helpers'import { getCommonNavigationAction, getTabNavigationAction, getTabResetAction,} from '#/lib/routes/navigation'import {type SharedNavTab, TAB_TO_NAV_ITEM} from '#/lib/routes/tab-to-nav-item'import {type RootNavigationProp} from '#/lib/routes/types'import {sanitizeHandle} from '#/lib/strings/handles'import {emitSoftReset} from '#/state/events'import {useModerationInboxUnreadCountQuery} from '#/state/queries/moderation-inbox'import {useUnreadNotifications} from '#/state/queries/notifications/unread'import {useProfileQuery} from '#/state/queries/profile'import {type SessionAccount, useSession} from '#/state/session'import {useSetDrawerOpen} from '#/state/shell'import {formatCount} from '#/view/com/util/numeric/format'import {UserAvatar} from '#/view/com/util/UserAvatar'import {NavSignupCard} from '#/view/shell/NavSignupCard'import {atoms as a, tokens, useTheme, web} from '#/alf'import {BetaTag} from '#/components/BetaTag'import {Button, ButtonIcon, ButtonText} from '#/components/Button'import {useDialogControl} from '#/components/Dialog'import {Divider} from '#/components/Divider'import {ArrowShareRight_Stroke2_Corner2_Rounded as ArrowShareRightIcon} from '#/components/icons/Arrow'import { Bell_Filled_Corner0_Rounded as BellFilledIcon, Bell_Stroke2_Corner0_Rounded as BellIcon,} from '#/components/icons/Bell'import { Bookmark_Filled_Corner0_Rounded as BookmarkFilledIcon, Bookmark_Stroke2_Corner0_Rounded as BookmarkIcon,} from '#/components/icons/Bookmark'import {BulletList_Stroke2_Corner0_Rounded as ListIcon} from '#/components/icons/BulletList'import {Earth_Stroke2_Corner0_Rounded as EarthIcon} from '#/components/icons/Earth'import { Hashtag_Filled_Corner0_Rounded as HashtagFilledIcon, Hashtag_Stroke2_Corner0_Rounded as HashtagIcon,} from '#/components/icons/Hashtag'import {Heart2_Stroke2_Corner0_Rounded as Heart} from '#/components/icons/Heart2'import { HomeOpen_Filled_Corner0_Rounded as HomeFilledIcon, HomeOpen_Stroke2_Corner0_Rounded as HomeIcon,} from '#/components/icons/Home'import { MagnifyingGlass_Filled_Stroke2_Corner0_Rounded as MagnifyingGlassFilledIcon, MagnifyingGlass_Stroke2_Corner0_Rounded as MagnifyingGlassIcon,} from '#/components/icons/MagnifyingGlass'import { Message_Stroke2_Corner0_Rounded as MessageIcon, Message_Stroke2_Corner0_Rounded_Filled as MessageFilledIcon,} from '#/components/icons/Message'import {SettingsGear2_Stroke2_Corner0_Rounded as SettingsIcon} from '#/components/icons/Settings'import { UserCircle_Filled_Corner0_Rounded as UserCircleFilledIcon, UserCircle_Stroke2_Corner0_Rounded as UserCircleIcon,} from '#/components/icons/UserCircle'import {InlineLinkText} from '#/components/Link'import {OTAChannelNotice} from '#/components/OTAChannelNotice'import {ProfileBadges} from '#/components/ProfileBadges'import {Text} from '#/components/Typography'import {useAnalytics} from '#/analytics'import {IS_NATIVE, IS_WEB} from '#/env'import {InviteFriendsDialog} from '#/features/inviteFriends'import {useActorStatus} from '#/features/liveNow'
const iconWidth = 26type SecondarySidebarTab = 'Atmosphere' | 'Feeds' | 'Lists' | 'Bookmarks' | 'Settings'const SECONDARY_TAB_ROUTES: Record< SecondarySidebarTab, 'AtmosphereTab' | 'FeedsTab' | 'ListsTab' | 'BookmarksTab' | 'SettingsTab'> = { Atmosphere: 'AtmosphereTab', Feeds: 'FeedsTab', Lists: 'ListsTab', Bookmarks: 'BookmarksTab', Settings: 'SettingsTab',}
let DrawerProfileCard = ({ account, onPressProfile, onPressShare,}: { account: SessionAccount onPressProfile: () => void onPressShare?: () => void}): React.ReactNode => { const {t: l, i18n} = useLingui() const t = useTheme() const {data: profile} = useProfileQuery({did: account.did}) const {isActive: live} = useActorStatus(profile)
return ( <TouchableOpacity testID="profileCardButton" accessibilityLabel={l`Profile`} accessibilityHint={l`Navigates to your profile`} onPress={onPressProfile} style={[a.gap_sm, a.pr_lg]}> <UserAvatar size={52} avatar={profile?.avatar} // See https://github.com/bluesky-social/social-app/pull/1801: usePlainRNImage={true} type={profile?.associated?.labeler ? 'labeler' : 'user'} live={live} /> <View style={[a.gap_2xs]}> <View style={[a.flex_row, a.align_center, a.gap_xs, a.flex_1]}> <Text emoji style={[ a.font_bold, a.text_xl, a.mt_2xs, a.leading_tight, a.flex_shrink, ]} numberOfLines={1}> {profile?.displayName || account.handle} </Text> {profile && <ProfileBadges profile={profile} size="lg" />} {onPressShare && ( <Pressable accessibilityRole="button" accessibilityLabel={l`Invite friends`} accessibilityHint={l`Opens the invite friends sheet to share your profile`} onPress={onPressShare} hitSlop={8} style={({pressed}) => [ a.ml_auto, { width: 32, height: 32, borderRadius: 16, backgroundColor: t.palette.contrast_50, alignItems: 'center', justifyContent: 'center', opacity: pressed ? 0.7 : 1, }, ]}> <ArrowShareRightIcon width={16} height={16} fill={t.palette.primary_500} /> </Pressable> )} </View> <Text emoji style={[t.atoms.text_contrast_medium, a.text_md, a.leading_tight]} numberOfLines={1}> {sanitizeHandle(account.handle, '@')} </Text> </View> <Text style={[a.text_md, t.atoms.text_contrast_medium]}> <Text style={[a.text_md, a.font_semi_bold]}> {formatCount(i18n, profile?.followersCount ?? 0)} </Text>{' '} {i18n._( plural(profile?.followersCount || 0, { one: 'follower', other: 'followers', }), )}{' '} ·{' '} <Text style={[a.text_md, a.font_semi_bold]}> {formatCount(i18n, profile?.followsCount ?? 0)} </Text>{' '} {i18n._( plural(profile?.followsCount || 0, { one: 'following', other: 'following', }), )} </Text> </TouchableOpacity> )}DrawerProfileCard = memo(DrawerProfileCard)export {DrawerProfileCard}
let DrawerContent = ({}: React.PropsWithoutRef<{}>): React.ReactNode => { const t = useTheme() const brand = useBrand() const insets = useSafeAreaInsets() const setDrawerOpen = useSetDrawerOpen() const navigation = useNavigation<RootNavigationProp>() const ax = useAnalytics() const { isAtHome, isAtSearch, isAtAtmosphere, isAtFeeds, isAtBookmarks, isAtNotifications, isAtMyProfile, isAtMessages, } = useNavigationTabState() const {hasSession, currentAccount} = useSession() const inviteFriendsControl = useDialogControl() const isAtmosphereExploreEnabled = ax.features.enabled( ax.features.AtmosphereScreenEnable, )
// events // =
const onPressTab = useCallback( (tab: SharedNavTab, surface: 'drawer' | 'drawerHeader' = 'drawer') => { ax.metric('nav:click', { item: TAB_TO_NAV_ITEM[tab], surface, }) const state: NavigationState = navigation.getState() setDrawerOpen(false) if (IS_WEB) { navigation.dispatch(getTabNavigationAction(tab, currentAccount?.handle)) } else { const tabState = getTabState(state, tab) if (tabState === TabState.InsideAtRoot) { emitSoftReset() } else if (tabState === TabState.Inside) { // find the correct navigator in which to pop-to-top const target = state.routes.find(route => route.name === `${tab}Tab`) ?.state?.key if (target) { // if we found it, trigger pop-to-top navigation.dispatch({ ...StackActions.popToTop(), target, }) } else { // fallback: reset navigation navigation.dispatch(getTabResetAction(tab)) } } else { navigation.dispatch(getTabNavigationAction(tab)) } } }, [navigation, setDrawerOpen, currentAccount, ax], )
const onPressHome = useCallback(() => onPressTab('Home'), [onPressTab])
const onPressSearch = useCallback(() => onPressTab('Search'), [onPressTab])
const onPressMessages = useCallback( () => onPressTab('Messages'), [onPressTab], )
const onPressNotifications = useCallback( () => onPressTab('Notifications'), [onPressTab], )
const onPressProfile = useCallback(() => { onPressTab('MyProfile') }, [onPressTab])
const onPressDrawerHeaderProfile = useCallback(() => { onPressTab('MyProfile', 'drawerHeader') }, [onPressTab])
const navigateToSecondaryTab = useCallback( (tab: SecondarySidebarTab) => { const state: NavigationState = navigation.getState() const tabState = getTabState(state, tab) const routeName = SECONDARY_TAB_ROUTES[tab] if (tabState === TabState.InsideAtRoot) { emitSoftReset() } else if (tabState === TabState.Inside) { const target = state.routes.find(route => route.name === routeName) ?.state?.key if (target) { navigation.dispatch({ ...StackActions.popToTop(), target, }) } else { navigation.dispatch(getTabResetAction(tab)) } } else { navigation.dispatch(getTabNavigationAction(tab)) } setDrawerOpen(false) }, [navigation, setDrawerOpen], )
const onPressMyFeeds = useCallback(() => { ax.metric('nav:click', {item: 'feeds', surface: 'drawer'}) if (IS_WEB) navigation.dispatch(getTabNavigationAction('Feeds')) else navigateToSecondaryTab('Feeds') if (IS_WEB) setDrawerOpen(false) }, [navigation, navigateToSecondaryTab, setDrawerOpen, ax])
const onPressAtmosphere = useCallback(() => { ax.metric('nav:click', {item: 'atmosphere', surface: 'drawer'}) if (IS_WEB) navigation.dispatch(getTabNavigationAction('Atmosphere')) else navigateToSecondaryTab('Atmosphere') if (IS_WEB) setDrawerOpen(false) }, [navigation, navigateToSecondaryTab, setDrawerOpen, ax])
const onPressLists = useCallback(() => { ax.metric('nav:click', {item: 'lists', surface: 'drawer'}) if (IS_WEB) navigation.dispatch(getTabNavigationAction('Lists')) else navigateToSecondaryTab('Lists') if (IS_WEB) setDrawerOpen(false) }, [navigation, navigateToSecondaryTab, setDrawerOpen, ax])
const onPressBookmarks = useCallback(() => { ax.metric('nav:click', {item: 'saved', surface: 'drawer'}) if (IS_WEB) navigation.dispatch(getTabNavigationAction('Bookmarks')) else navigateToSecondaryTab('Bookmarks') if (IS_WEB) setDrawerOpen(false) }, [navigation, navigateToSecondaryTab, setDrawerOpen, ax])
const onPressSettings = useCallback(() => { ax.metric('nav:click', {item: 'settings', surface: 'drawer'}) if (IS_WEB) navigation.dispatch(getTabNavigationAction('Settings')) else navigateToSecondaryTab('Settings') if (IS_WEB) setDrawerOpen(false) }, [navigation, navigateToSecondaryTab, setDrawerOpen, ax])
const onPressSupport = useCallback(() => { navigation.dispatch( getCommonNavigationAction( {name: 'Support', params: undefined}, navigation.getState(), ), ) setDrawerOpen(false) }, [navigation, setDrawerOpen])
const onPressFeedback = useCallback(() => { void Linking.openURL( FEEDBACK_FORM_URL({ email: currentAccount?.email, handle: currentAccount?.handle, }), ) }, [currentAccount])
const onPressHelp = useCallback(() => { void Linking.openURL(HELP_DESK_URL) }, [])
const onPressDiscuss = useCallback(() => { if (brand.web.links.community) { void Linking.openURL(brand.web.links.community) } }, [brand.web.links.community])
const onPressContribute = useCallback(() => { const contribute = brand.web.links.contribute if (contribute) { // `contribute` may be a site-relative path (e.g. "/support"), which // Linking.openURL can't resolve on native. Resolve it against the brand // domain first. const url = contribute.startsWith('http') ? contribute : `${brand.web.domains.main.replace(/\/$/, '')}${contribute}` void Linking.openURL(url) } }, [brand.web.links.contribute, brand.web.domains.main])
// rendering // =
return ( <View testID="drawer" style={[a.flex_1, a.border_r, t.atoms.bg, t.atoms.border_contrast_low]}> <ScrollView style={[a.flex_1]} contentContainerStyle={[ { paddingTop: Math.max( insets.top + a.pt_xl.paddingTop, a.pt_xl.paddingTop, ), }, ]}> <View style={[a.px_xl]}> {hasSession && currentAccount ? ( <DrawerProfileCard account={currentAccount} onPressProfile={onPressDrawerHeaderProfile} onPressShare={ IS_NATIVE ? () => { ax.metric('invite:dialog:open', {logContext: 'Drawer'}) setDrawerOpen(false) inviteFriendsControl.open() } : undefined } /> ) : ( <View style={[a.pr_xl]}> <NavSignupCard /> </View> )}
<OTAChannelNotice style={[a.mt_lg]} />
<Divider style={[a.mt_xl, a.mb_sm]} /> </View>
{hasSession ? ( <> <SearchMenuItem isActive={isAtSearch} onPress={onPressSearch} /> <HomeMenuItem isActive={isAtHome} onPress={onPressHome} /> <ChatMenuItem isActive={isAtMessages} onPress={onPressMessages} /> <NotificationsMenuItem isActive={isAtNotifications} onPress={onPressNotifications} /> {isAtmosphereExploreEnabled && ( <AtmosphereMenuItem isActive={isAtAtmosphere} onPress={onPressAtmosphere} /> )} <FeedsMenuItem isActive={isAtFeeds} onPress={onPressMyFeeds} /> <ListsMenuItem onPress={onPressLists} /> <BookmarksMenuItem isActive={isAtBookmarks} onPress={onPressBookmarks} /> <ProfileMenuItem isActive={isAtMyProfile} onPress={onPressProfile} /> <SettingsMenuItem onPress={onPressSettings} /> <SupportMenuItem onPress={onPressSupport} /> </> ) : ( <> <HomeMenuItem isActive={isAtHome} onPress={onPressHome} /> <FeedsMenuItem isActive={isAtFeeds} onPress={onPressMyFeeds} /> <SearchMenuItem isActive={isAtSearch} onPress={onPressSearch} /> </> )}
<View style={[a.px_xl]}> <Divider style={[a.mb_xl, a.mt_sm]} /> <ExtraLinks /> </View> </ScrollView>
<DrawerFooter onPressFeedback={onPressFeedback} onPressHelp={onPressHelp} onPressDiscuss={onPressDiscuss} onPressContribute={onPressContribute} showDiscuss={!!brand.web.links.community} showContribute={!!brand.web.links.contribute} /> <InviteFriendsDialog control={inviteFriendsControl} /> </View> )}DrawerContent = memo(DrawerContent)export {DrawerContent}
let DrawerFooter = ({ onPressFeedback, onPressHelp, onPressDiscuss, onPressContribute, showDiscuss, showContribute,}: { onPressFeedback: () => void onPressHelp: () => void onPressDiscuss: () => void onPressContribute: () => void showDiscuss: boolean showContribute: boolean}): React.ReactNode => { const {t: l} = useLingui() const insets = useSafeAreaInsets() return ( <View style={[ a.flex_row, a.gap_sm, a.flex_wrap, a.pl_xl, a.pt_md, { paddingBottom: Math.max( insets.bottom + tokens.space.xs, tokens.space.xl, ), }, ]}> <Button label={l`Send feedback`} size="small" variant="solid" color="secondary" onPress={onPressFeedback}> <ButtonIcon icon={MessageIcon} position="left" /> <ButtonText> <Trans>Feedback</Trans> </ButtonText> </Button> {showDiscuss ? ( <Button label={l`Begin Discussion`} size="small" variant="solid" color="secondary" onPress={onPressDiscuss}> <ButtonIcon icon={MessageIcon} position="left" /> <ButtonText> <Trans>Discussion</Trans> </ButtonText> </Button> ) : null} <Button label={l`Get help`} size="small" variant="outline" color="secondary" onPress={onPressHelp} style={{ backgroundColor: 'transparent', }}> <ButtonText> <Trans>Help</Trans> </ButtonText> </Button> {showContribute ? ( <Button label={l`Support Us`} size="small" variant="outline" color="secondary" onPress={onPressContribute} style={{ backgroundColor: 'transparent', }}> <ButtonText> <Trans>Support Us</Trans> </ButtonText> </Button> ) : null} </View> )}DrawerFooter = memo(DrawerFooter)
interface MenuItemProps extends ComponentProps<typeof PressableScale> { icon: JSX.Element label: string count?: string bold?: boolean beta?: boolean}
let SearchMenuItem = ({ isActive, onPress,}: { isActive: boolean onPress: () => void}): React.ReactNode => { const {t: l} = useLingui() const t = useTheme() return ( <MenuItem icon={ isActive ? ( <MagnifyingGlassFilledIcon style={[t.atoms.text]} width={iconWidth} /> ) : ( <MagnifyingGlassIcon style={[t.atoms.text]} width={iconWidth} /> ) } label={l`Explore`} bold={isActive} onPress={onPress} /> )}SearchMenuItem = memo(SearchMenuItem)
function AtmosphereMenuItem({ isActive, onPress,}: { isActive: boolean onPress: () => void}) { const {t: l} = useLingui() const t = useTheme()
return ( <MenuItem icon={<EarthIcon style={[t.atoms.text]} width={iconWidth} />} label={l`Atmosphere`} beta bold={isActive} onPress={onPress} /> )}
let HomeMenuItem = ({ isActive, onPress,}: { isActive: boolean onPress: () => void}): React.ReactNode => { const {t: l} = useLingui() const t = useTheme() return ( <MenuItem icon={ isActive ? ( <HomeFilledIcon style={[t.atoms.text]} width={iconWidth} /> ) : ( <HomeIcon style={[t.atoms.text]} width={iconWidth} /> ) } label={l`Home`} bold={isActive} onPress={onPress} /> )}HomeMenuItem = memo(HomeMenuItem)
let ChatMenuItem = ({ isActive, onPress,}: { isActive: boolean onPress: () => void}): React.ReactNode => { const {t: l} = useLingui() const t = useTheme() return ( <MenuItem icon={ isActive ? ( <MessageFilledIcon style={[t.atoms.text]} width={iconWidth} /> ) : ( <MessageIcon style={[t.atoms.text]} width={iconWidth} /> ) } label={l`Chat`} bold={isActive} onPress={onPress} /> )}ChatMenuItem = memo(ChatMenuItem)
let NotificationsMenuItem = ({ isActive, onPress,}: { isActive: boolean onPress: () => void}): React.ReactNode => { const {t: l} = useLingui() const t = useTheme() const numUnreadNotifications = useUnreadNotifications() return ( <MenuItem icon={ isActive ? ( <BellFilledIcon style={[t.atoms.text]} width={iconWidth} /> ) : ( <BellIcon style={[t.atoms.text]} width={iconWidth} /> ) } label={l`Notifications`} accessibilityHint={ numUnreadNotifications === '' ? '' : plural(numUnreadNotifications ?? 0, { one: '# unread item', other: '# unread items', }) } count={numUnreadNotifications} bold={isActive} onPress={onPress} /> )}NotificationsMenuItem = memo(NotificationsMenuItem)
let FeedsMenuItem = ({ isActive, onPress,}: { isActive: boolean onPress: () => void}): React.ReactNode => { const {t: l} = useLingui() const t = useTheme() return ( <MenuItem icon={ isActive ? ( <HashtagFilledIcon width={iconWidth} style={[t.atoms.text]} /> ) : ( <HashtagIcon width={iconWidth} style={[t.atoms.text]} /> ) } label={l`Feeds`} bold={isActive} onPress={onPress} /> )}FeedsMenuItem = memo(FeedsMenuItem)
let ListsMenuItem = ({onPress}: {onPress: () => void}): React.ReactNode => { const {t: l} = useLingui() const t = useTheme()
return ( <MenuItem icon={<ListIcon style={[t.atoms.text]} width={iconWidth} />} label={l`Lists`} onPress={onPress} /> )}ListsMenuItem = memo(ListsMenuItem)
let BookmarksMenuItem = ({ isActive, onPress,}: { isActive: boolean onPress: () => void}): React.ReactNode => { const {t: l} = useLingui() const t = useTheme()
return ( <MenuItem icon={ isActive ? ( <BookmarkFilledIcon style={[t.atoms.text]} width={iconWidth} /> ) : ( <BookmarkIcon style={[t.atoms.text]} width={iconWidth} /> ) } label={l({message: 'Saved', context: 'link to bookmarks screen'})} onPress={onPress} /> )}BookmarksMenuItem = memo(BookmarksMenuItem)
let ProfileMenuItem = ({ isActive, onPress,}: { isActive: boolean onPress: () => void}): React.ReactNode => { const {t: l} = useLingui() const t = useTheme() return ( <MenuItem icon={ isActive ? ( <UserCircleFilledIcon style={[t.atoms.text]} width={iconWidth} /> ) : ( <UserCircleIcon style={[t.atoms.text]} width={iconWidth} /> ) } label={l`Profile`} onPress={onPress} /> )}ProfileMenuItem = memo(ProfileMenuItem)
let SettingsMenuItem = ({onPress}: {onPress: () => void}): React.ReactNode => { const {i18n, t: l} = useLingui() const t = useTheme() const ax = useAnalytics() const isModerationInboxEnabled = ax.features.enabled( ax.features.ModerationInboxEnable, ) const unreadCountQuery = useModerationInboxUnreadCountQuery( isModerationInboxEnabled, ) const unreadCount = isModerationInboxEnabled ? (unreadCountQuery.data?.unreadCounts.total ?? 0) : 0 const count = unreadCount > 0 ? unreadCount >= UNREAD_NOTIFICATION_CAP ? l({ message: `${i18n.number(UNREAD_NOTIFICATION_CAP - 1)}+`, comment: 'Displayed when the number of notifications exceeds the cap – for example, 99+', }) : i18n.number(unreadCount) : undefined
return ( <MenuItem icon={<SettingsIcon style={[t.atoms.text]} width={iconWidth} />} label={l`Settings`} count={count} accessibilityHint={ unreadCount > 0 ? plural(unreadCount, { one: '# unread update', other: '# unread updates', }) : '' } onPress={onPress} /> )}SettingsMenuItem = memo(SettingsMenuItem)
let SupportMenuItem = ({onPress}: {onPress: () => void}): React.ReactNode => { const {t: l} = useLingui() const t = useTheme() return ( <MenuItem icon={<Heart style={[t.atoms.text]} width={iconWidth} />} label={l`Support Us`} onPress={onPress} /> )}SupportMenuItem = memo(SupportMenuItem)
function MenuItem({ icon, label, count, bold, beta, onPress, accessibilityHint,}: MenuItemProps) { const t = useTheme() const {t: l} = useLingui() return ( <Button testID={`menuItemButton-${label}`} onPress={onPress} accessibilityRole="tab" accessibilityHint={accessibilityHint} label={beta ? l`${label}, Beta` : label}> {({hovered, pressed}) => ( <View style={[ a.flex_1, a.flex_row, a.align_center, a.gap_md, a.py_md, a.px_xl, (hovered || pressed) && t.atoms.bg_contrast_25, ]}> <View style={[a.relative]}> {icon} {count ? ( <View style={[ a.absolute, a.inset_0, a.align_end, {top: -4, right: a.gap_sm.gap * -1}, ]}> <View style={[ a.rounded_full, { right: count.length === 1 ? 6 : 0, paddingHorizontal: 4, paddingVertical: 1, backgroundColor: t.palette.primary_500, }, ]}> <Text style={[ a.text_xs, a.leading_tight, a.font_semi_bold, { fontVariant: ['tabular-nums'], color: t.palette.white, }, ]} numberOfLines={1}> {count} </Text> </View> </View> ) : undefined} </View> <View style={[a.flex_1, a.flex_row, a.align_center, a.gap_sm]}> <Text style={[ a.flex_shrink, a.text_2xl, bold && a.font_bold, web(a.leading_snug), ]} numberOfLines={1}> {label} </Text> {beta && <BetaTag />} </View> </View> )} </Button> )}
function ExtraLinks() { const {t: l} = useLingui() const brand = useBrand()
return ( <View style={[a.flex_col, a.gap_md, a.flex_wrap]}> <InlineLinkText style={[a.text_md]} label={l`Terms of Service`} to={brand.web.links.tos}> <Trans>Terms of Service</Trans> </InlineLinkText> <InlineLinkText style={[a.text_md]} to={brand.web.links.privacy} label={l`Privacy Policy`}> <Trans>Privacy Policy</Trans> </InlineLinkText> </View> )}