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