Bluesky app fork with some witchin' additions 馃挮
1import {msg} from '@lingui/core/macro'
2import {useLingui} from '@lingui/react'
3
4import {useRequireAuth, useSession} from '#/state/session'
5import {EventStopper} from '#/view/com/util/EventStopper'
6import {useTheme} from '#/alf'
7import {CloseQuote_Stroke2_Corner1_Rounded as Quote} from '#/components/icons/Quote'
8import {Repost_Stroke2_Corner2_Rounded as Repost} from '#/components/icons/Repost'
9import * as Menu from '#/components/Menu'
10import {
11 PostControlButton,
12 PostControlButtonIcon,
13 PostControlButtonText,
14} from './PostControlButton'
15import {useFormatPostStatCount} from './util'
16
17interface Props {
18 isReposted: boolean
19 repostCount?: number
20 onRepost: () => void
21 onQuote: () => void
22 onLongPress?: () => void
23 big?: boolean
24 embeddingDisabled: boolean
25}
26
27export const RepostButton = ({
28 isReposted,
29 repostCount,
30 onRepost,
31 onQuote,
32 onLongPress,
33 big,
34 embeddingDisabled,
35}: Props) => {
36 const t = useTheme()
37 const {_} = useLingui()
38 const {hasSession} = useSession()
39 const requireAuth = useRequireAuth()
40 const formatPostStatCount = useFormatPostStatCount()
41
42 return hasSession ? (
43 <EventStopper onKeyDown={false}>
44 <Menu.Root>
45 <Menu.Trigger label={_(msg`Repost or quote post`)}>
46 {({props}) => {
47 return (
48 <PostControlButton
49 testID="repostBtn"
50 active={isReposted}
51 activeColor={t.palette.positive_500}
52 label={props.accessibilityLabel}
53 big={big}
54 onLongPress={onLongPress}
55 {...props}>
56 <PostControlButtonIcon icon={Repost} />
57 {typeof repostCount !== 'undefined' && repostCount > 0 && (
58 <PostControlButtonText testID="repostCount">
59 {formatPostStatCount(repostCount)}
60 </PostControlButtonText>
61 )}
62 </PostControlButton>
63 )
64 }}
65 </Menu.Trigger>
66 <Menu.Outer style={{minWidth: 170}}>
67 <Menu.Item
68 label={
69 isReposted
70 ? _(msg`Undo repost`)
71 : _(msg({message: `Repost`, context: `action`}))
72 }
73 testID="repostDropdownRepostBtn"
74 onPress={onRepost}>
75 <Menu.ItemText>
76 {isReposted
77 ? _(msg`Undo repost`)
78 : _(msg({message: `Repost`, context: `action`}))}
79 </Menu.ItemText>
80 <Menu.ItemIcon icon={Repost} position="right" />
81 </Menu.Item>
82 <Menu.Item
83 disabled={embeddingDisabled}
84 label={
85 embeddingDisabled
86 ? _(msg`Quote posts disabled`)
87 : _(msg`Quote post`)
88 }
89 testID="repostDropdownQuoteBtn"
90 onPress={onQuote}>
91 <Menu.ItemText>
92 {embeddingDisabled
93 ? _(msg`Quote posts disabled`)
94 : _(msg`Quote post`)}
95 </Menu.ItemText>
96 <Menu.ItemIcon icon={Quote} position="right" />
97 </Menu.Item>
98 </Menu.Outer>
99 </Menu.Root>
100 </EventStopper>
101 ) : (
102 <PostControlButton
103 onPress={() => requireAuth(() => {})}
104 active={isReposted}
105 activeColor={t.palette.positive_500}
106 label={_(msg`Repost or quote post`)}
107 big={big}>
108 <PostControlButtonIcon icon={Repost} />
109 {typeof repostCount !== 'undefined' && repostCount > 0 && (
110 <PostControlButtonText testID="repostCount">
111 {formatPostStatCount(repostCount)}
112 </PostControlButtonText>
113 )}
114 </PostControlButton>
115 )
116}