forked from
jollywhoppers.com/witchsky.app
Bluesky app fork with some witchin' additions 馃挮
1import {type StyleProp, View, type ViewStyle} from 'react-native'
2import {type AppBskyFeedDefs, type ComAtprotoLabelDefs} from '@atproto/api'
3import {msg, Plural, Trans} from '@lingui/macro'
4import {useLingui} from '@lingui/react'
5
6import {useSession} from '#/state/session'
7import {atoms as a} from '#/alf'
8import {
9 Button,
10 ButtonIcon,
11 type ButtonSize,
12 ButtonText,
13} from '#/components/Button'
14import {CircleInfo_Stroke2_Corner0_Rounded as CircleInfo} from '#/components/icons/CircleInfo'
15import {
16 LabelsOnMeDialog,
17 useLabelsOnMeDialogControl,
18} from '#/components/moderation/LabelsOnMeDialog'
19
20export function LabelsOnMe({
21 type,
22 labels,
23 size,
24 style,
25}: {
26 type: 'account' | 'content'
27 labels: ComAtprotoLabelDefs.Label[] | undefined
28 size?: ButtonSize
29 style?: StyleProp<ViewStyle>
30}) {
31 const {_} = useLingui()
32 const {currentAccount} = useSession()
33 const control = useLabelsOnMeDialogControl()
34
35 if (!labels || !currentAccount) {
36 return null
37 }
38 labels = labels.filter(l => !l.val.startsWith('!'))
39 if (!labels.length) {
40 return null
41 }
42
43 return (
44 <View style={[a.flex_row, style]}>
45 <LabelsOnMeDialog control={control} labels={labels} type={type} />
46
47 <Button
48 variant="solid"
49 color="secondary"
50 size={size || 'small'}
51 label={_(msg`View information about these labels`)}
52 onPress={() => {
53 control.open()
54 }}>
55 <ButtonIcon position="left" icon={CircleInfo} />
56 <ButtonText style={[a.leading_snug]}>
57 {type === 'account' ? (
58 <Trans>
59 <Plural
60 value={labels.length}
61 one="# label has"
62 other="# labels have"
63 />{' '}
64 been placed on this account
65 </Trans>
66 ) : (
67 <Trans>
68 <Plural
69 value={labels.length}
70 one="# label has"
71 other="# labels have"
72 />{' '}
73 been placed on this content
74 </Trans>
75 )}
76 </ButtonText>
77 </Button>
78 </View>
79 )
80}
81
82export function LabelsOnMyPost({
83 post,
84 style,
85}: {
86 post: AppBskyFeedDefs.PostView
87 style?: StyleProp<ViewStyle>
88}) {
89 const {currentAccount} = useSession()
90 if (post.author.did !== currentAccount?.did) {
91 return null
92 }
93 return (
94 <LabelsOnMe type="content" labels={post.labels} size="tiny" style={style} />
95 )
96}