Something went wrong. Try again.
Bluesky app fork with some witchin' additions 💫 forked from jollywhoppers.com/witchsky.app
Something went wrong. Try again.
4.9 kB · 145 lines
TSX
at build
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146import {plural} from '@lingui/core/macro'import {useLingui} from '@lingui/react/macro'
import {type CountsMetricsDisplay} from '#/lib/metrics-display'import {useRequireAuth, useSession} from '#/state/session'import {EventStopper} from '#/view/com/util/EventStopper'import {useTheme} from '#/alf'import {CloseQuote_Stroke2_Corner1_Rounded as QuoteIcon} from '#/components/icons/Quote'import {RepostRepost_Stroke2_Corner2_Rounded as BumpRepostIcon} from '#/components/icons/Repost'import {Repost_Stroke2_Corner2_Rounded as RepostIcon} from '#/components/icons/Repost'import * as Menu from '#/components/Menu'import {MetricCountLabel} from '#/components/PostControls/MetricCountLabel'import {PostControlButton, PostControlButtonIcon} from './PostControlButton'
export interface RepostButtonProps { isReposted: boolean repostCount?: number onRepost: () => void onBumpRepost?: () => void onLongPress?: () => void metricsDisplay?: CountsMetricsDisplay onQuote: (openAccountSwitcher?: boolean) => void big?: boolean embeddingDisabled: boolean longPressToQuote?: boolean}
export function RepostButtonMenu({ isReposted, repostCount, onRepost, onQuote, onBumpRepost, onLongPress, metricsDisplay = 'visible', big, embeddingDisabled, longPressToQuote = false,}: RepostButtonProps): React.ReactNode { const t = useTheme() const {t: l} = useLingui() const {hasSession} = useSession() const requireAuth = useRequireAuth()
return hasSession ? ( <EventStopper onKeyDown={false}> <Menu.Root> <Menu.Trigger label={l`Repost or quote post`}> {({props}) => ( <PostControlButton testID="repostBtn" active={isReposted} activeColor={t.palette.positive_500} label={props.accessibilityLabel} big={big} {...props} onLongPress={ onLongPress ?? (longPressToQuote ? () => requireAuth(() => { if (embeddingDisabled) { props.onPress() } else { onQuote() } }) : undefined) }> <PostControlButtonIcon icon={RepostIcon} /> {typeof repostCount !== 'undefined' && repostCount > 0 && ( <MetricCountLabel display={metricsDisplay} count={repostCount} testID="repostCount" labelOnly={plural(repostCount, { one: 'repost', other: 'reposts', })} /> )} </PostControlButton> )} </Menu.Trigger> <Menu.Outer> <Menu.Group> {isReposted && onBumpRepost && ( <Menu.Item testID="repostDropdownBumpBtn" label={l`Bump repost`} onPress={onBumpRepost}> <Menu.ItemText>{l`Bump repost`}</Menu.ItemText> <Menu.ItemIcon icon={BumpRepostIcon} position="right" /> </Menu.Item> )} <Menu.Item label={ isReposted ? l`Undo repost` : l({message: `Repost`, context: 'action'}) } testID="repostDropdownRepostBtn" onPress={onRepost}> <Menu.ItemText> {isReposted ? l`Undo repost` : l({message: `Repost`, context: 'action'})} </Menu.ItemText> <Menu.ItemIcon icon={RepostIcon} position="right" /> </Menu.Item> <Menu.Item disabled={embeddingDisabled} label={ embeddingDisabled ? l`Quote posts disabled` : l`Quote post` } testID="repostDropdownQuoteBtn" onPress={() => onQuote()}> <Menu.ItemText> {embeddingDisabled ? l`Quote posts disabled` : l`Quote post`} </Menu.ItemText> <Menu.ItemIcon icon={QuoteIcon} position="right" /> </Menu.Item> </Menu.Group> </Menu.Outer> </Menu.Root> </EventStopper> ) : ( <PostControlButton onPress={() => requireAuth(() => {})} active={isReposted} activeColor={t.palette.positive_500} label={l`Repost or quote post`} big={big}> <PostControlButtonIcon icon={RepostIcon} /> {typeof repostCount !== 'undefined' && repostCount > 0 && ( <MetricCountLabel display={metricsDisplay} count={repostCount} testID="repostCount" labelOnly={plural(repostCount, {one: 'repost', other: 'reposts'})} /> )} </PostControlButton> )}