Render dropdown menu items lazily (#6437)

This commit is contained in:
dan
2024-11-17 03:15:03 +00:00
committed by GitHub
parent ddf2a64a72
commit e9fe8d90ef
+72 -41
View File
@@ -102,12 +102,77 @@ let PostDropdownBtn = ({
timestamp: string timestamp: string
threadgateRecord?: AppBskyFeedThreadgate.Record threadgateRecord?: AppBskyFeedThreadgate.Record
}): React.ReactNode => { }): React.ReactNode => {
const {hasSession, currentAccount} = useSession()
const theme = useTheme() const theme = useTheme()
const alf = useAlf() const alf = useAlf()
const {gtMobile} = useBreakpoints()
const {_} = useLingui() const {_} = useLingui()
const defaultCtrlColor = theme.palette.default.postCtrl const defaultCtrlColor = theme.palette.default.postCtrl
return (
<EventStopper onKeyDown={false}>
<Menu.Root>
<Menu.Trigger label={_(msg`Open post options menu`)}>
{({props, state}) => {
return (
<Pressable
{...props}
hitSlop={hitSlop}
testID={testID}
style={[
style,
a.rounded_full,
(state.hovered || state.pressed) && [
alf.atoms.bg_contrast_25,
],
]}>
<DotsHorizontal
fill={defaultCtrlColor}
style={{pointerEvents: 'none'}}
size={size}
/>
</Pressable>
)
}}
</Menu.Trigger>
<Menu.Outer>
<PostDropdownMenuItems
testID={testID}
post={post}
postFeedContext={postFeedContext}
record={record}
richText={richText}
timestamp={timestamp}
threadgateRecord={threadgateRecord}
/>
</Menu.Outer>
</Menu.Root>
</EventStopper>
)
}
PostDropdownBtn = memo(PostDropdownBtn)
export {PostDropdownBtn}
let PostDropdownMenuItems = ({
post,
postFeedContext,
record,
richText,
timestamp,
threadgateRecord,
}: {
testID: string
post: Shadow<AppBskyFeedDefs.PostView>
postFeedContext: string | undefined
record: AppBskyFeedPost.Record
richText: RichTextAPI
style?: StyleProp<ViewStyle>
hitSlop?: PressableProps['hitSlop']
size?: 'lg' | 'md' | 'sm'
timestamp: string
threadgateRecord?: AppBskyFeedThreadgate.Record
}): React.ReactNode => {
const {hasSession, currentAccount} = useSession()
const {gtMobile} = useBreakpoints()
const {_} = useLingui()
const langPrefs = useLanguagePrefs() const langPrefs = useLanguagePrefs()
const {mutateAsync: deletePostMutate} = usePostDeleteMutation() const {mutateAsync: deletePostMutate} = usePostDeleteMutation()
const {mutateAsync: pinPostMutate, isPending: isPinPending} = const {mutateAsync: pinPostMutate, isPending: isPinPending} =
@@ -360,33 +425,7 @@ let PostDropdownBtn = ({
}, [isPinned, pinPostMutate, postCid, postUri]) }, [isPinned, pinPostMutate, postCid, postUri])
return ( return (
<EventStopper onKeyDown={false}> <>
<Menu.Root>
<Menu.Trigger label={_(msg`Open post options menu`)}>
{({props, state}) => {
return (
<Pressable
{...props}
hitSlop={hitSlop}
testID={testID}
style={[
style,
a.rounded_full,
(state.hovered || state.pressed) && [
alf.atoms.bg_contrast_25,
],
]}>
<DotsHorizontal
fill={defaultCtrlColor}
style={{pointerEvents: 'none'}}
size={size}
/>
</Pressable>
)
}}
</Menu.Trigger>
<Menu.Outer>
{isAuthor && ( {isAuthor && (
<> <>
<Menu.Group> <Menu.Group>
@@ -508,9 +547,7 @@ let PostDropdownBtn = ({
} }
onPress={onToggleThreadMute}> onPress={onToggleThreadMute}>
<Menu.ItemText> <Menu.ItemText>
{isThreadMuted {isThreadMuted ? _(msg`Unmute thread`) : _(msg`Mute thread`)}
? _(msg`Unmute thread`)
: _(msg`Mute thread`)}
</Menu.ItemText> </Menu.ItemText>
<Menu.ItemIcon <Menu.ItemIcon
icon={isThreadMuted ? Unmute : Mute} icon={isThreadMuted ? Unmute : Mute}
@@ -630,9 +667,7 @@ let PostDropdownBtn = ({
<Menu.Item <Menu.Item
testID="postDropdownEditPostInteractions" testID="postDropdownEditPostInteractions"
label={_(msg`Edit interaction settings`)} label={_(msg`Edit interaction settings`)}
onPress={() => onPress={() => postInteractionSettingsDialogControl.open()}
postInteractionSettingsDialogControl.open()
}
{...(isAuthor {...(isAuthor
? Platform.select({ ? Platform.select({
web: { web: {
@@ -660,8 +695,6 @@ let PostDropdownBtn = ({
</Menu.Group> </Menu.Group>
</> </>
)} )}
</Menu.Outer>
</Menu.Root>
<Prompt.Basic <Prompt.Basic
control={deletePromptControl} control={deletePromptControl}
@@ -745,9 +778,7 @@ let PostDropdownBtn = ({
onConfirm={onToggleReplyVisibility} onConfirm={onToggleReplyVisibility}
confirmButtonCta={_(msg`Yes, hide`)} confirmButtonCta={_(msg`Yes, hide`)}
/> />
</EventStopper> </>
) )
} }
PostDropdownMenuItems = memo(PostDropdownMenuItems)
PostDropdownBtn = memo(PostDropdownBtn)
export {PostDropdownBtn}