update type imports, remove forwardRef
This commit is contained in:
@@ -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 {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 {Text, type TextProps} from '#/components/Typography'
|
||||
|
||||
const PostControlContext = React.createContext<{
|
||||
const PostControlContext = createContext<{
|
||||
big?: boolean
|
||||
active?: boolean
|
||||
color?: {color: string}
|
||||
}>({})
|
||||
|
||||
// Base button style, which the the other ones extend
|
||||
export const PostControlButton = React.forwardRef<
|
||||
View,
|
||||
ButtonProps & {
|
||||
active?: boolean
|
||||
big?: boolean
|
||||
color?: string
|
||||
activeColor?: string
|
||||
}
|
||||
>(
|
||||
(
|
||||
{onPress, onLongPress, children, big, active, activeColor, ...props},
|
||||
ref,
|
||||
) => {
|
||||
const t = useTheme()
|
||||
const playHaptic = useHaptics()
|
||||
export function PostControlButton({
|
||||
ref,
|
||||
onPress,
|
||||
onLongPress,
|
||||
children,
|
||||
big,
|
||||
active,
|
||||
activeColor,
|
||||
...props
|
||||
}: ButtonProps & {
|
||||
ref?: React.Ref<View>
|
||||
active?: boolean
|
||||
big?: boolean
|
||||
color?: string
|
||||
activeColor?: string
|
||||
}) {
|
||||
const t = useTheme()
|
||||
const playHaptic = useHaptics()
|
||||
|
||||
const ctx = React.useMemo(
|
||||
() => ({
|
||||
big,
|
||||
active,
|
||||
color: {
|
||||
color: activeColor && active ? activeColor : t.palette.contrast_500,
|
||||
},
|
||||
}),
|
||||
[big, active, activeColor, t.palette.contrast_500],
|
||||
)
|
||||
const ctx = useMemo(
|
||||
() => ({
|
||||
big,
|
||||
active,
|
||||
color: {
|
||||
color: activeColor && active ? activeColor : t.palette.contrast_500,
|
||||
},
|
||||
}),
|
||||
[big, active, activeColor, t.palette.contrast_500],
|
||||
)
|
||||
|
||||
const style = useMemo(
|
||||
() => [
|
||||
a.flex_row,
|
||||
a.align_center,
|
||||
a.gap_xs,
|
||||
a.bg_transparent,
|
||||
{padding: 5},
|
||||
],
|
||||
[],
|
||||
)
|
||||
const style = useMemo(
|
||||
() => [
|
||||
a.flex_row,
|
||||
a.align_center,
|
||||
a.gap_xs,
|
||||
a.bg_transparent,
|
||||
{padding: 5},
|
||||
],
|
||||
[],
|
||||
)
|
||||
|
||||
const handlePress = useMemo(() => {
|
||||
if (!onPress) return
|
||||
return (evt: GestureResponderEvent) => {
|
||||
playHaptic('Light')
|
||||
onPress(evt)
|
||||
}
|
||||
}, [onPress, playHaptic])
|
||||
const handlePress = useMemo(() => {
|
||||
if (!onPress) return
|
||||
return (evt: GestureResponderEvent) => {
|
||||
playHaptic('Light')
|
||||
onPress(evt)
|
||||
}
|
||||
}, [onPress, playHaptic])
|
||||
|
||||
const handleLongPress = useMemo(() => {
|
||||
if (!onLongPress) return
|
||||
return (evt: GestureResponderEvent) => {
|
||||
playHaptic('Heavy')
|
||||
onLongPress(evt)
|
||||
}
|
||||
}, [onLongPress, playHaptic])
|
||||
const handleLongPress = useMemo(() => {
|
||||
if (!onLongPress) return
|
||||
return (evt: GestureResponderEvent) => {
|
||||
playHaptic('Heavy')
|
||||
onLongPress(evt)
|
||||
}
|
||||
}, [onLongPress, playHaptic])
|
||||
|
||||
return (
|
||||
<Button
|
||||
ref={ref}
|
||||
onPress={handlePress}
|
||||
onLongPress={handleLongPress}
|
||||
style={style}
|
||||
hoverStyle={t.atoms.bg_contrast_25}
|
||||
shape="round"
|
||||
variant="ghost"
|
||||
color="secondary"
|
||||
hitSlop={POST_CTRL_HITSLOP}
|
||||
{...props}>
|
||||
{typeof children === 'function' ? (
|
||||
args => (
|
||||
<PostControlContext.Provider value={ctx}>
|
||||
{children(args)}
|
||||
</PostControlContext.Provider>
|
||||
)
|
||||
) : (
|
||||
return (
|
||||
<Button
|
||||
ref={ref}
|
||||
onPress={handlePress}
|
||||
onLongPress={handleLongPress}
|
||||
style={style}
|
||||
hoverStyle={t.atoms.bg_contrast_25}
|
||||
shape="round"
|
||||
variant="ghost"
|
||||
color="secondary"
|
||||
hitSlop={POST_CTRL_HITSLOP}
|
||||
{...props}>
|
||||
{typeof children === 'function' ? (
|
||||
args => (
|
||||
<PostControlContext.Provider value={ctx}>
|
||||
{children}
|
||||
{children(args)}
|
||||
</PostControlContext.Provider>
|
||||
)}
|
||||
</Button>
|
||||
)
|
||||
},
|
||||
)
|
||||
PostControlButton.displayName = 'PostControlButton'
|
||||
)
|
||||
) : (
|
||||
<PostControlContext.Provider value={ctx}>
|
||||
{children}
|
||||
</PostControlContext.Provider>
|
||||
)}
|
||||
</Button>
|
||||
)
|
||||
}
|
||||
|
||||
export function PostControlButtonIcon({
|
||||
icon: Comp,
|
||||
|
||||
@@ -26,7 +26,6 @@ import {
|
||||
type CommonNavigatorParams,
|
||||
type NavigationProp,
|
||||
} from '#/lib/routes/types'
|
||||
import {shareText} from '#/lib/sharing'
|
||||
import {logEvent} from '#/lib/statsig/statsig'
|
||||
import {richTextToString} from '#/lib/strings/rich-text-helpers'
|
||||
import {toShareUrl} from '#/lib/strings/url-helpers'
|
||||
@@ -58,7 +57,6 @@ import {
|
||||
PostInteractionSettingsDialog,
|
||||
usePrefetchPostInteractionSettings,
|
||||
} 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 {BubbleQuestion_Stroke2_Corner0_Rounded as Translate} from '#/components/icons/Bubble'
|
||||
import {Clipboard_Stroke2_Corner2_Rounded as ClipboardIcon} from '#/components/icons/Clipboard'
|
||||
@@ -85,7 +83,6 @@ import {
|
||||
useReportDialogControl,
|
||||
} from '#/components/moderation/ReportDialog'
|
||||
import * as Prompt from '#/components/Prompt'
|
||||
import {useDevMode} from '#/storage/hooks/dev-mode'
|
||||
import * as bsky from '#/types/bsky'
|
||||
|
||||
let PostMenuItems = ({
|
||||
@@ -131,7 +128,6 @@ let PostMenuItems = ({
|
||||
const hideReplyConfirmControl = useDialogControl()
|
||||
const {mutateAsync: toggleReplyVisibility} =
|
||||
useToggleReplyVisibilityMutation()
|
||||
const [devModeEnabled] = useDevMode()
|
||||
|
||||
const postUri = post.uri
|
||||
const postCid = post.cid
|
||||
@@ -390,14 +386,6 @@ let PostMenuItems = ({
|
||||
}
|
||||
}
|
||||
|
||||
const onShareATURI = () => {
|
||||
shareText(postUri)
|
||||
}
|
||||
|
||||
const onShareAuthorDID = () => {
|
||||
shareText(postAuthor.did)
|
||||
}
|
||||
|
||||
const onReportMisclassification = () => {
|
||||
const url = `https://docs.google.com/forms/d/e/1FAIpQLSd0QPqhNFksDQf1YyOos7r1ofCLvmrKAH1lU042TaS3GAZaWQ/viewform?entry.1756031717=${toShareUrl(
|
||||
href,
|
||||
@@ -485,11 +473,9 @@ let PostMenuItems = ({
|
||||
DISCOVER_DEBUG_DIDS[currentAccount?.did ?? ''] && (
|
||||
<Menu.Item
|
||||
testID="postDropdownReportMisclassificationBtn"
|
||||
label={_(msg`Assign topic - help train Discover!`)}
|
||||
label={_(msg`Assign topic for algo`)}
|
||||
onPress={onReportMisclassification}>
|
||||
<Menu.ItemText>
|
||||
{_(msg`Assign topic - help train Discover!`)}
|
||||
</Menu.ItemText>
|
||||
<Menu.ItemText>{_(msg`Assign topic for algo`)}</Menu.ItemText>
|
||||
<Menu.ItemIcon icon={AtomIcon} position="right" />
|
||||
</Menu.Item>
|
||||
)}
|
||||
@@ -682,28 +668,6 @@ let PostMenuItems = ({
|
||||
</>
|
||||
)}
|
||||
</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>
|
||||
|
||||
Reference in New Issue
Block a user