From e9fe8d90ef5e9ca2ed4bc9649794c5288fb1232d Mon Sep 17 00:00:00 2001 From: dan Date: Sun, 17 Nov 2024 03:15:03 +0000 Subject: Render dropdown menu items lazily (#6437) --- src/view/com/util/forms/PostDropdownBtn.tsx | 587 +++++++++++++++------------- 1 file changed, 309 insertions(+), 278 deletions(-) (limited to 'src') diff --git a/src/view/com/util/forms/PostDropdownBtn.tsx b/src/view/com/util/forms/PostDropdownBtn.tsx index 1cd4841a5..e71332279 100644 --- a/src/view/com/util/forms/PostDropdownBtn.tsx +++ b/src/view/com/util/forms/PostDropdownBtn.tsx @@ -102,12 +102,77 @@ let PostDropdownBtn = ({ timestamp: string threadgateRecord?: AppBskyFeedThreadgate.Record }): React.ReactNode => { - const {hasSession, currentAccount} = useSession() const theme = useTheme() const alf = useAlf() - const {gtMobile} = useBreakpoints() const {_} = useLingui() const defaultCtrlColor = theme.palette.default.postCtrl + return ( + + + + {({props, state}) => { + return ( + + + + ) + }} + + + + + + + ) +} + +PostDropdownBtn = memo(PostDropdownBtn) +export {PostDropdownBtn} + +let PostDropdownMenuItems = ({ + post, + postFeedContext, + record, + richText, + timestamp, + threadgateRecord, +}: { + testID: string + post: Shadow + postFeedContext: string | undefined + record: AppBskyFeedPost.Record + richText: RichTextAPI + style?: StyleProp + 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 {mutateAsync: deletePostMutate} = usePostDeleteMutation() const {mutateAsync: pinPostMutate, isPending: isPinPending} = @@ -360,308 +425,276 @@ let PostDropdownBtn = ({ }, [isPinned, pinPostMutate, postCid, postUri]) return ( - - - - {({props, state}) => { - return ( - - - - ) - }} - + <> + {isAuthor && ( + <> + + + + {isPinned + ? _(msg`Unpin from profile`) + : _(msg`Pin to your profile`)} + + + + + + + )} - - {isAuthor && ( - <> - - - - {isPinned - ? _(msg`Unpin from profile`) - : _(msg`Pin to your profile`)} - - - - - - - )} + + {(!hideInPWI || hasSession) && ( + <> + + {_(msg`Translate`)} + + - - {(!hideInPWI || hasSession) && ( - <> - - {_(msg`Translate`)} - - + + {_(msg`Copy post text`)} + + + + )} - - {_(msg`Copy post text`)} - - - - )} + {hasSession && ( + sendViaChatControl.open()}> + + Send via direct message + + + + )} - {hasSession && ( - sendViaChatControl.open()}> - - Send via direct message - - - - )} + { + if (showLoggedOutWarning) { + loggedOutWarningPromptControl.open() + } else { + onSharePost() + } + }}> + + {isWeb ? _(msg`Copy link to post`) : _(msg`Share`)} + + + + + {canEmbed && ( + embedPostControl.open()}> + {_(msg`Embed post`)} + + + )} + + + {hasSession && feedFeedback.enabled && ( + <> + + + + {_(msg`Show more like this`)} + + { - if (showLoggedOutWarning) { - loggedOutWarningPromptControl.open() - } else { - onSharePost() - } - }}> + testID="postDropdownShowLessBtn" + label={_(msg`Show less like this`)} + onPress={onPressShowLess}> + {_(msg`Show less like this`)} + + + + + )} + + {hasSession && ( + <> + + + - {isWeb ? _(msg`Copy link to post`) : _(msg`Share`)} + {isThreadMuted ? _(msg`Unmute thread`) : _(msg`Mute thread`)} - + - {canEmbed && ( - embedPostControl.open()}> - {_(msg`Embed post`)} - - - )} + mutedWordsDialogControl.open()}> + {_(msg`Mute words & tags`)} + + + + )} - {hasSession && feedFeedback.enabled && ( - <> - - - - {_(msg`Show more like this`)} - - - + {hasSession && + (canHideReplyForEveryone || canDetachQuote || canHidePostForMe) && ( + <> + + + {canHidePostForMe && ( - {_(msg`Show less like this`)} - + testID="postDropdownHideBtn" + label={ + isReply + ? _(msg`Hide reply for me`) + : _(msg`Hide post for me`) + } + onPress={() => hidePromptControl.open()}> + + {isReply + ? _(msg`Hide reply for me`) + : _(msg`Hide post for me`)} + + - - - )} - - {hasSession && ( - <> - - + )} + {canHideReplyForEveryone && ( + onPress={ + isReplyHiddenByThreadgate + ? onToggleReplyVisibility + : () => hideReplyConfirmControl.open() + }> - {isThreadMuted - ? _(msg`Unmute thread`) - : _(msg`Mute thread`)} + {isReplyHiddenByThreadgate + ? _(msg`Show reply for everyone`) + : _(msg`Hide reply for everyone`)} + )} + {canDetachQuote && ( mutedWordsDialogControl.open()}> - {_(msg`Mute words & tags`)} - + disabled={isDetachPending} + testID="postDropdownHideBtn" + label={ + quoteEmbed.isDetached + ? _(msg`Re-attach quote`) + : _(msg`Detach quote`) + } + onPress={ + quoteEmbed.isDetached + ? onToggleQuotePostAttachment + : () => quotePostDetachConfirmControl.open() + }> + + {quoteEmbed.isDetached + ? _(msg`Re-attach quote`) + : _(msg`Detach quote`)} + + - - - )} + )} + + + )} + + {hasSession && ( + <> + + + {!isAuthor && ( + reportDialogControl.open()}> + {_(msg`Report post`)} + + + )} - {hasSession && - (canHideReplyForEveryone || canDetachQuote || canHidePostForMe) && ( + {isAuthor && ( <> - - - {canHidePostForMe && ( - hidePromptControl.open()}> - - {isReply - ? _(msg`Hide reply for me`) - : _(msg`Hide post for me`)} - - - - )} - {canHideReplyForEveryone && ( - hideReplyConfirmControl.open() - }> - - {isReplyHiddenByThreadgate - ? _(msg`Show reply for everyone`) - : _(msg`Hide reply for everyone`)} - - - - )} - - {canDetachQuote && ( - quotePostDetachConfirmControl.open() - }> - - {quoteEmbed.isDetached - ? _(msg`Re-attach quote`) - : _(msg`Detach quote`)} - - - - )} - + postInteractionSettingsDialogControl.open()} + {...(isAuthor + ? Platform.select({ + web: { + onHoverIn: prefetchPostInteractionSettings, + }, + native: { + onPressIn: prefetchPostInteractionSettings, + }, + }) + : {})}> + + {_(msg`Edit interaction settings`)} + + + + deletePromptControl.open()}> + {_(msg`Delete post`)} + + )} - - {hasSession && ( - <> - - - {!isAuthor && ( - reportDialogControl.open()}> - {_(msg`Report post`)} - - - )} - - {isAuthor && ( - <> - - postInteractionSettingsDialogControl.open() - } - {...(isAuthor - ? Platform.select({ - web: { - onHoverIn: prefetchPostInteractionSettings, - }, - native: { - onPressIn: prefetchPostInteractionSettings, - }, - }) - : {})}> - - {_(msg`Edit interaction settings`)} - - - - deletePromptControl.open()}> - {_(msg`Delete post`)} - - - - )} - - - )} - - + + + )} - + ) } - -PostDropdownBtn = memo(PostDropdownBtn) -export {PostDropdownBtn} +PostDropdownMenuItems = memo(PostDropdownMenuItems) -- cgit 1.4.1