forked from
jollywhoppers.com/witchsky.app
Bluesky app fork with some witchin' additions 馃挮
1import {msg} from '@lingui/macro'
2import {useLingui} from '@lingui/react'
3
4import {getTerminology} from '#/lib/strings/terminology'
5import {useTerminologyPreference} from '#/state/preferences'
6import {useRequireAuth} from '#/state/session'
7import {useSession} from '#/state/session'
8import {EventStopper} from '#/view/com/util/EventStopper'
9import {useTheme} from '#/alf'
10import {CloseQuote_Stroke2_Corner1_Rounded as Quote} from '#/components/icons/Quote'
11import {Repost_Stroke2_Corner2_Rounded as Repost} from '#/components/icons/Repost'
12import * as Menu from '#/components/Menu'
13import {
14 PostControlButton,
15 PostControlButtonIcon,
16 PostControlButtonText,
17} from './PostControlButton'
18import {useFormatPostStatCount} from './util'
19
20interface Props {
21 isReposted: boolean
22 repostCount?: number
23 onRepost: () => void
24 onQuote: () => void
25 big?: boolean
26 embeddingDisabled: boolean
27}
28
29export const RepostButton = ({
30 isReposted,
31 repostCount,
32 onRepost,
33 onQuote,
34 big,
35 embeddingDisabled,
36}: Props) => {
37 const t = useTheme()
38 const {_} = useLingui()
39 const terminologyPreference = useTerminologyPreference()
40 const {hasSession} = useSession()
41 const requireAuth = useRequireAuth()
42 const formatPostStatCount = useFormatPostStatCount()
43
44 return hasSession ? (
45 <EventStopper onKeyDown={false}>
46 <Menu.Root>
47 <Menu.Trigger label={_(getTerminology(terminologyPreference, {
48 skeet: msg`Reskeet or quote skeet`,
49 post: msg`Repost or quote post`,
50 spell: msg`Respell or quote spell`,
51 }))}>
52 {({props}) => {
53 return (
54 <PostControlButton
55 testID="repostBtn"
56 active={isReposted}
57 activeColor={t.palette.positive_500}
58 label={props.accessibilityLabel}
59 big={big}
60 {...props}>
61 <PostControlButtonIcon icon={Repost} />
62 {typeof repostCount !== 'undefined' && repostCount > 0 && (
63 <PostControlButtonText testID="repostCount">
64 {formatPostStatCount(repostCount)}
65 </PostControlButtonText>
66 )}
67 </PostControlButton>
68 )
69 }}
70 </Menu.Trigger>
71 <Menu.Outer style={{minWidth: 170}}>
72 <Menu.Item
73 label={
74 isReposted
75 ? _(getTerminology(terminologyPreference, {
76 skeet: msg`Undo reskeet`,
77 post: msg`Undo repost`,
78 spell: msg`Undo respell`,
79 }))
80 : _(getTerminology(terminologyPreference, {
81 skeet: msg({message: `Reskeet`, context: `action`}),
82 post: msg({message: `Repost`, context: `action`}),
83 spell: msg({message: `Respell`, context: `action`}),
84 }))
85 }
86 testID="repostDropdownRepostBtn"
87 onPress={onRepost}>
88 <Menu.ItemText>
89 {isReposted
90 ? _(getTerminology(terminologyPreference, {
91 skeet: msg`Undo reskeet`,
92 post: msg`Undo repost`,
93 spell: msg`Undo respell`,
94 }))
95 : _(getTerminology(terminologyPreference, {
96 skeet: msg({message: `Reskeet`, context: `action`}),
97 post: msg({message: `Repost`, context: `action`}),
98 spell: msg({message: `Respell`, context: `action`}),
99 }))}
100 </Menu.ItemText>
101 <Menu.ItemIcon icon={Repost} position="right" />
102 </Menu.Item>
103 <Menu.Item
104 disabled={embeddingDisabled}
105 label={
106 embeddingDisabled
107 ? _(getTerminology(terminologyPreference, {
108 skeet: msg`Quote skeets disabled`,
109 post: msg`Quote posts disabled`,
110 spell: msg`Quote spells disabled`,
111 }))
112 : _(getTerminology(terminologyPreference, {
113 skeet: msg`Quote skeet`,
114 post: msg`Quote post`,
115 spell: msg`Quote spell`,
116 }))
117 }
118 testID="repostDropdownQuoteBtn"
119 onPress={onQuote}>
120 <Menu.ItemText>
121 {embeddingDisabled
122 ? _(getTerminology(terminologyPreference, {
123 skeet: msg`Quote skeets disabled`,
124 post: msg`Quote posts disabled`,
125 spell: msg`Quote spells disabled`,
126 }))
127 : _(getTerminology(terminologyPreference, {
128 skeet: msg`Quote skeet`,
129 post: msg`Quote post`,
130 spell: msg`Quote spell`,
131 }))}
132 </Menu.ItemText>
133 <Menu.ItemIcon icon={Quote} position="right" />
134 </Menu.Item>
135 </Menu.Outer>
136 </Menu.Root>
137 </EventStopper>
138 ) : (
139 <PostControlButton
140 onPress={() => requireAuth(() => {})}
141 active={isReposted}
142 activeColor={t.palette.positive_500}
143 label={_(getTerminology(terminologyPreference, {
144 skeet: msg`Reskeet or quote skeet`,
145 post: msg`Repost or quote post`,
146 spell: msg`Respell or quote spell`,
147 }))}
148 big={big}>
149 <PostControlButtonIcon icon={Repost} />
150 {typeof repostCount !== 'undefined' && repostCount > 0 && (
151 <PostControlButtonText testID="repostCount">
152 {formatPostStatCount(repostCount)}
153 </PostControlButtonText>
154 )}
155 </PostControlButton>
156 )
157}