update type imports, remove forwardRef

This commit is contained in:
Samuel Newman
2025-05-20 15:44:29 +03:00
parent 5ad62b8ce4
commit b1727842cf
2 changed files with 80 additions and 115 deletions
@@ -1,4 +1,4 @@
import React, {useContext, useMemo} from 'react' import {createContext, useContext, useMemo} from 'react'
import {type GestureResponderEvent, type View} from 'react-native' import {type GestureResponderEvent, type View} from 'react-native'
import {POST_CTRL_HITSLOP} from '#/lib/constants' import {POST_CTRL_HITSLOP} from '#/lib/constants'
@@ -8,95 +8,96 @@ import {Button, type ButtonProps} from '#/components/Button'
import {type Props as SVGIconProps} from '#/components/icons/common' import {type Props as SVGIconProps} from '#/components/icons/common'
import {Text, type TextProps} from '#/components/Typography' import {Text, type TextProps} from '#/components/Typography'
const PostControlContext = React.createContext<{ const PostControlContext = createContext<{
big?: boolean big?: boolean
active?: boolean active?: boolean
color?: {color: string} color?: {color: string}
}>({}) }>({})
// Base button style, which the the other ones extend // Base button style, which the the other ones extend
export const PostControlButton = React.forwardRef< export function PostControlButton({
View, ref,
ButtonProps & { onPress,
active?: boolean onLongPress,
big?: boolean children,
color?: string big,
activeColor?: string active,
} activeColor,
>( ...props
( }: ButtonProps & {
{onPress, onLongPress, children, big, active, activeColor, ...props}, ref?: React.Ref<View>
ref, active?: boolean
) => { big?: boolean
const t = useTheme() color?: string
const playHaptic = useHaptics() activeColor?: string
}) {
const t = useTheme()
const playHaptic = useHaptics()
const ctx = React.useMemo( const ctx = useMemo(
() => ({ () => ({
big, big,
active, active,
color: { color: {
color: activeColor && active ? activeColor : t.palette.contrast_500, color: activeColor && active ? activeColor : t.palette.contrast_500,
}, },
}), }),
[big, active, activeColor, t.palette.contrast_500], [big, active, activeColor, t.palette.contrast_500],
) )
const style = useMemo( const style = useMemo(
() => [ () => [
a.flex_row, a.flex_row,
a.align_center, a.align_center,
a.gap_xs, a.gap_xs,
a.bg_transparent, a.bg_transparent,
{padding: 5}, {padding: 5},
], ],
[], [],
) )
const handlePress = useMemo(() => { const handlePress = useMemo(() => {
if (!onPress) return if (!onPress) return
return (evt: GestureResponderEvent) => { return (evt: GestureResponderEvent) => {
playHaptic('Light') playHaptic('Light')
onPress(evt) onPress(evt)
} }
}, [onPress, playHaptic]) }, [onPress, playHaptic])
const handleLongPress = useMemo(() => { const handleLongPress = useMemo(() => {
if (!onLongPress) return if (!onLongPress) return
return (evt: GestureResponderEvent) => { return (evt: GestureResponderEvent) => {
playHaptic('Heavy') playHaptic('Heavy')
onLongPress(evt) onLongPress(evt)
} }
}, [onLongPress, playHaptic]) }, [onLongPress, playHaptic])
return ( return (
<Button <Button
ref={ref} ref={ref}
onPress={handlePress} onPress={handlePress}
onLongPress={handleLongPress} onLongPress={handleLongPress}
style={style} style={style}
hoverStyle={t.atoms.bg_contrast_25} hoverStyle={t.atoms.bg_contrast_25}
shape="round" shape="round"
variant="ghost" variant="ghost"
color="secondary" color="secondary"
hitSlop={POST_CTRL_HITSLOP} hitSlop={POST_CTRL_HITSLOP}
{...props}> {...props}>
{typeof children === 'function' ? ( {typeof children === 'function' ? (
args => ( args => (
<PostControlContext.Provider value={ctx}>
{children(args)}
</PostControlContext.Provider>
)
) : (
<PostControlContext.Provider value={ctx}> <PostControlContext.Provider value={ctx}>
{children} {children(args)}
</PostControlContext.Provider> </PostControlContext.Provider>
)} )
</Button> ) : (
) <PostControlContext.Provider value={ctx}>
}, {children}
) </PostControlContext.Provider>
PostControlButton.displayName = 'PostControlButton' )}
</Button>
)
}
export function PostControlButtonIcon({ export function PostControlButtonIcon({
icon: Comp, icon: Comp,
@@ -26,7 +26,6 @@ import {
type CommonNavigatorParams, type CommonNavigatorParams,
type NavigationProp, type NavigationProp,
} from '#/lib/routes/types' } from '#/lib/routes/types'
import {shareText} from '#/lib/sharing'
import {logEvent} from '#/lib/statsig/statsig' import {logEvent} from '#/lib/statsig/statsig'
import {richTextToString} from '#/lib/strings/rich-text-helpers' import {richTextToString} from '#/lib/strings/rich-text-helpers'
import {toShareUrl} from '#/lib/strings/url-helpers' import {toShareUrl} from '#/lib/strings/url-helpers'
@@ -58,7 +57,6 @@ import {
PostInteractionSettingsDialog, PostInteractionSettingsDialog,
usePrefetchPostInteractionSettings, usePrefetchPostInteractionSettings,
} from '#/components/dialogs/PostInteractionSettingsDialog' } from '#/components/dialogs/PostInteractionSettingsDialog'
import {ArrowOutOfBox_Stroke2_Corner0_Rounded as Share} from '#/components/icons/ArrowOutOfBox'
import {Atom_Stroke2_Corner0_Rounded as AtomIcon} from '#/components/icons/Atom' import {Atom_Stroke2_Corner0_Rounded as AtomIcon} from '#/components/icons/Atom'
import {BubbleQuestion_Stroke2_Corner0_Rounded as Translate} from '#/components/icons/Bubble' import {BubbleQuestion_Stroke2_Corner0_Rounded as Translate} from '#/components/icons/Bubble'
import {Clipboard_Stroke2_Corner2_Rounded as ClipboardIcon} from '#/components/icons/Clipboard' import {Clipboard_Stroke2_Corner2_Rounded as ClipboardIcon} from '#/components/icons/Clipboard'
@@ -85,7 +83,6 @@ import {
useReportDialogControl, useReportDialogControl,
} from '#/components/moderation/ReportDialog' } from '#/components/moderation/ReportDialog'
import * as Prompt from '#/components/Prompt' import * as Prompt from '#/components/Prompt'
import {useDevMode} from '#/storage/hooks/dev-mode'
import * as bsky from '#/types/bsky' import * as bsky from '#/types/bsky'
let PostMenuItems = ({ let PostMenuItems = ({
@@ -131,7 +128,6 @@ let PostMenuItems = ({
const hideReplyConfirmControl = useDialogControl() const hideReplyConfirmControl = useDialogControl()
const {mutateAsync: toggleReplyVisibility} = const {mutateAsync: toggleReplyVisibility} =
useToggleReplyVisibilityMutation() useToggleReplyVisibilityMutation()
const [devModeEnabled] = useDevMode()
const postUri = post.uri const postUri = post.uri
const postCid = post.cid const postCid = post.cid
@@ -390,14 +386,6 @@ let PostMenuItems = ({
} }
} }
const onShareATURI = () => {
shareText(postUri)
}
const onShareAuthorDID = () => {
shareText(postAuthor.did)
}
const onReportMisclassification = () => { const onReportMisclassification = () => {
const url = `https://docs.google.com/forms/d/e/1FAIpQLSd0QPqhNFksDQf1YyOos7r1ofCLvmrKAH1lU042TaS3GAZaWQ/viewform?entry.1756031717=${toShareUrl( const url = `https://docs.google.com/forms/d/e/1FAIpQLSd0QPqhNFksDQf1YyOos7r1ofCLvmrKAH1lU042TaS3GAZaWQ/viewform?entry.1756031717=${toShareUrl(
href, href,
@@ -485,11 +473,9 @@ let PostMenuItems = ({
DISCOVER_DEBUG_DIDS[currentAccount?.did ?? ''] && ( DISCOVER_DEBUG_DIDS[currentAccount?.did ?? ''] && (
<Menu.Item <Menu.Item
testID="postDropdownReportMisclassificationBtn" testID="postDropdownReportMisclassificationBtn"
label={_(msg`Assign topic - help train Discover!`)} label={_(msg`Assign topic for algo`)}
onPress={onReportMisclassification}> onPress={onReportMisclassification}>
<Menu.ItemText> <Menu.ItemText>{_(msg`Assign topic for algo`)}</Menu.ItemText>
{_(msg`Assign topic - help train Discover!`)}
</Menu.ItemText>
<Menu.ItemIcon icon={AtomIcon} position="right" /> <Menu.ItemIcon icon={AtomIcon} position="right" />
</Menu.Item> </Menu.Item>
)} )}
@@ -682,28 +668,6 @@ let PostMenuItems = ({
</> </>
)} )}
</Menu.Group> </Menu.Group>
{devModeEnabled ? (
<>
<Menu.Divider />
<Menu.Group>
<Menu.Item
testID="postAtUriShareBtn"
label={_(msg`Copy post at:// URI`)}
onPress={onShareATURI}>
<Menu.ItemText>{_(msg`Copy post at:// URI`)}</Menu.ItemText>
<Menu.ItemIcon icon={Share} position="right" />
</Menu.Item>
<Menu.Item
testID="postAuthorDIDShareBtn"
label={_(msg`Copy author DID`)}
onPress={onShareAuthorDID}>
<Menu.ItemText>{_(msg`Copy author DID`)}</Menu.ItemText>
<Menu.ItemIcon icon={Share} position="right" />
</Menu.Item>
</Menu.Group>
</>
) : null}
</> </>
)} )}
</Menu.Outer> </Menu.Outer>