mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
at remove-hackfix 182 lines 5.8 kB view raw
1import {memo, useMemo} from 'react' 2import {AtUri} from '@atproto/api' 3import {msg, Trans} from '@lingui/macro' 4import {useLingui} from '@lingui/react' 5import {useNavigation} from '@react-navigation/native' 6 7import {makeProfileLink} from '#/lib/routes/links' 8import {type NavigationProp} from '#/lib/routes/types' 9import {shareText, shareUrl} from '#/lib/sharing' 10import {toShareUrl} from '#/lib/strings/url-helpers' 11import {logger} from '#/logger' 12import {isWeb} from '#/platform/detection' 13import {useAgeAssurance} from '#/state/ageAssurance/useAgeAssurance' 14import {useProfileShadow} from '#/state/cache/profile-shadow' 15import {useSession} from '#/state/session' 16import {useBreakpoints} from '#/alf' 17import {useDialogControl} from '#/components/Dialog' 18import {EmbedDialog} from '#/components/dialogs/Embed' 19import {SendViaChatDialog} from '#/components/dms/dialogs/ShareViaChatDialog' 20import {ChainLink_Stroke2_Corner0_Rounded as ChainLinkIcon} from '#/components/icons/ChainLink' 21import {Clipboard_Stroke2_Corner2_Rounded as ClipboardIcon} from '#/components/icons/Clipboard' 22import {CodeBrackets_Stroke2_Corner0_Rounded as CodeBracketsIcon} from '#/components/icons/CodeBrackets' 23import {PaperPlane_Stroke2_Corner0_Rounded as Send} from '#/components/icons/PaperPlane' 24import * as Menu from '#/components/Menu' 25import {useDevMode} from '#/storage/hooks/dev-mode' 26import {type ShareMenuItemsProps} from './ShareMenuItems.types' 27 28let ShareMenuItems = ({ 29 post, 30 record, 31 timestamp, 32 onShare: onShareProp, 33}: ShareMenuItemsProps): React.ReactNode => { 34 const {hasSession} = useSession() 35 const {gtMobile} = useBreakpoints() 36 const {_} = useLingui() 37 const navigation = useNavigation<NavigationProp>() 38 const embedPostControl = useDialogControl() 39 const sendViaChatControl = useDialogControl() 40 const [devModeEnabled] = useDevMode() 41 const {isAgeRestricted} = useAgeAssurance() 42 43 const postUri = post.uri 44 const postCid = post.cid 45 const postAuthor = useProfileShadow(post.author) 46 47 const href = useMemo(() => { 48 const urip = new AtUri(postUri) 49 return makeProfileLink(postAuthor, 'post', urip.rkey) 50 }, [postUri, postAuthor]) 51 52 const hideInPWI = useMemo(() => { 53 return !!postAuthor.labels?.find( 54 label => label.val === '!no-unauthenticated', 55 ) 56 }, [postAuthor]) 57 58 const onCopyLink = () => { 59 logger.metric('share:press:copyLink', {}, {statsig: true}) 60 const url = toShareUrl(href) 61 shareUrl(url) 62 onShareProp() 63 } 64 65 const onSelectChatToShareTo = (conversation: string) => { 66 logger.metric('share:press:dmSelected', {}, {statsig: true}) 67 navigation.navigate('MessagesConversation', { 68 conversation, 69 embed: postUri, 70 }) 71 } 72 73 const canEmbed = isWeb && gtMobile && !hideInPWI 74 75 const onShareATURI = () => { 76 shareText(postUri) 77 } 78 79 const onShareAuthorDID = () => { 80 shareText(postAuthor.did) 81 } 82 83 const copyLinkItem = ( 84 <Menu.Item 85 testID="postDropdownShareBtn" 86 label={_(msg`Copy link to post`)} 87 onPress={onCopyLink}> 88 <Menu.ItemText> 89 <Trans>Copy link to post</Trans> 90 </Menu.ItemText> 91 <Menu.ItemIcon icon={ChainLinkIcon} position="right" /> 92 </Menu.Item> 93 ) 94 95 return ( 96 <> 97 <Menu.Outer> 98 {!hideInPWI && copyLinkItem} 99 100 {hasSession && !isAgeRestricted && ( 101 <Menu.Item 102 testID="postDropdownSendViaDMBtn" 103 label={_(msg`Send via direct message`)} 104 onPress={() => { 105 logger.metric('share:press:openDmSearch', {}, {statsig: true}) 106 sendViaChatControl.open() 107 }}> 108 <Menu.ItemText> 109 <Trans>Send via direct message</Trans> 110 </Menu.ItemText> 111 <Menu.ItemIcon icon={Send} position="right" /> 112 </Menu.Item> 113 )} 114 115 {canEmbed && ( 116 <Menu.Item 117 testID="postDropdownEmbedBtn" 118 label={_(msg`Embed post`)} 119 onPress={() => { 120 logger.metric('share:press:embed', {}, {statsig: true}) 121 embedPostControl.open() 122 }}> 123 <Menu.ItemText>{_(msg`Embed post`)}</Menu.ItemText> 124 <Menu.ItemIcon icon={CodeBracketsIcon} position="right" /> 125 </Menu.Item> 126 )} 127 128 {hideInPWI && ( 129 <> 130 {hasSession && <Menu.Divider />} 131 {copyLinkItem} 132 <Menu.LabelText style={{maxWidth: 220}}> 133 <Trans>Note: This post is only visible to logged-in users.</Trans> 134 </Menu.LabelText> 135 </> 136 )} 137 138 {devModeEnabled && ( 139 <> 140 <Menu.Divider /> 141 <Menu.Item 142 testID="postAtUriShareBtn" 143 label={_(msg`Copy post at:// URI`)} 144 onPress={onShareATURI}> 145 <Menu.ItemText> 146 <Trans>Copy post at:// URI</Trans> 147 </Menu.ItemText> 148 <Menu.ItemIcon icon={ClipboardIcon} position="right" /> 149 </Menu.Item> 150 <Menu.Item 151 testID="postAuthorDIDShareBtn" 152 label={_(msg`Copy author DID`)} 153 onPress={onShareAuthorDID}> 154 <Menu.ItemText> 155 <Trans>Copy author DID</Trans> 156 </Menu.ItemText> 157 <Menu.ItemIcon icon={ClipboardIcon} position="right" /> 158 </Menu.Item> 159 </> 160 )} 161 </Menu.Outer> 162 163 {canEmbed && ( 164 <EmbedDialog 165 control={embedPostControl} 166 postCid={postCid} 167 postUri={postUri} 168 record={record} 169 postAuthor={postAuthor} 170 timestamp={timestamp} 171 /> 172 )} 173 174 <SendViaChatDialog 175 control={sendViaChatControl} 176 onSelectChat={onSelectChatToShareTo} 177 /> 178 </> 179 ) 180} 181ShareMenuItems = memo(ShareMenuItems) 182export {ShareMenuItems}