forked from
jollywhoppers.com/witchsky.app
Bluesky app fork with some witchin' additions 馃挮
1import {View} from 'react-native'
2import {type AppBskyActorDefs} from '@atproto/api'
3import {msg, plural} from '@lingui/macro'
4import {useLingui} from '@lingui/react'
5
6import {makeProfileLink} from '#/lib/routes/links'
7import {getTerminology} from '#/lib/strings/terminology'
8import {type Shadow} from '#/state/cache/types'
9import {useTerminologyPreference} from '#/state/preferences'
10import {useDisableFollowersMetrics} from '#/state/preferences/disable-followers-metrics'
11import {useDisableFollowingMetrics} from '#/state/preferences/disable-following-metrics'
12import {useDisablePostsMetrics} from '#/state/preferences/disable-posts-metrics'
13import {formatCount} from '#/view/com/util/numeric/format'
14import {atoms as a, useTheme} from '#/alf'
15import {InlineLinkText} from '#/components/Link'
16import {Text} from '#/components/Typography'
17
18export function ProfileHeaderMetrics({
19 profile,
20}: {
21 profile: Shadow<AppBskyActorDefs.ProfileViewDetailed>
22}) {
23 const t = useTheme()
24 const {_, i18n} = useLingui()
25 const terminologyPreference = useTerminologyPreference()
26 const following = formatCount(i18n, profile.followsCount || 0)
27 const followers = formatCount(i18n, profile.followersCount || 0)
28 const pluralizedFollowers = plural(profile.followersCount || 0, {
29 one: 'follower',
30 other: 'followers',
31 })
32 const pluralizedFollowings = plural(profile.followsCount || 0, {
33 one: 'following',
34 other: 'following',
35 })
36
37 // disable metrics
38 const disableFollowersMetrics = useDisableFollowersMetrics()
39 const disableFollowingMetrics = useDisableFollowingMetrics()
40 const disablePostsMetrics = useDisablePostsMetrics()
41
42 return (
43 <>
44 {disableFollowersMetrics && disableFollowingMetrics && disablePostsMetrics ? ( null ) :
45 <View
46 style={[a.flex_row, a.gap_sm, a.align_center]}
47 pointerEvents="box-none">
48 {!disableFollowersMetrics ? (
49 <InlineLinkText
50 testID="profileHeaderFollowersButton"
51 style={[a.flex_row, t.atoms.text]}
52 to={makeProfileLink(profile, 'followers')}
53 label={`${profile.followersCount || 0} ${pluralizedFollowers}`}>
54 <Text style={[a.font_semi_bold, a.text_md]}>{followers} </Text>
55 <Text style={[t.atoms.text_contrast_medium, a.text_md]}>
56 {pluralizedFollowers}
57 </Text>
58 </InlineLinkText>
59 ) : null}
60 {!disableFollowingMetrics ? (
61 <InlineLinkText
62 testID="profileHeaderFollowsButton"
63 style={[a.flex_row, t.atoms.text]}
64 to={makeProfileLink(profile, 'follows')}
65 label={_(msg`${profile.followsCount || 0} following`)}>
66 <Text style={[a.font_semi_bold, a.text_md]}>{following} </Text>
67 <Text style={[t.atoms.text_contrast_medium, a.text_md]}>
68 {pluralizedFollowings}
69 </Text>
70 </InlineLinkText>
71 ) : null}
72 {!disablePostsMetrics ? (
73 <Text style={[a.font_semi_bold, t.atoms.text, a.text_md]}>
74 {formatCount(i18n, profile.postsCount || 0)}{' '}
75 <Text style={[t.atoms.text_contrast_medium, a.font_normal, a.text_md]}>
76 {_(getTerminology(terminologyPreference, {
77 skeet: msg`${plural(profile.postsCount || 0, {one: 'skeet', other: 'skeets'})}`,
78 post: msg`${plural(profile.postsCount || 0, {one: 'post', other: 'posts'})}`,
79 spell: msg`${plural(profile.postsCount || 0, {one: 'spell', other: 'spells'})}`,
80 }))}
81 </Text>
82 </Text>
83 ) : null}
84 </View>
85 }
86 </>
87 )
88}