mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
at static-click 72 lines 1.9 kB view raw
1import React from 'react' 2import {View} from 'react-native' 3import {AppBskyActorDefs} from '@atproto/api' 4import {msg} from '@lingui/macro' 5import {useLingui} from '@lingui/react' 6 7import {logEvent} from '#/lib/statsig/statsig' 8import {useMaybeConvoForUser} from '#/state/queries/messages/get-convo-for-members' 9import {atoms as a, useTheme} from '#/alf' 10import {ButtonIcon} from '#/components/Button' 11import {canBeMessaged} from '#/components/dms/util' 12import {Message_Stroke2_Corner0_Rounded as Message} from '#/components/icons/Message' 13import {Link} from '#/components/Link' 14 15export function MessageProfileButton({ 16 profile, 17}: { 18 profile: AppBskyActorDefs.ProfileView 19}) { 20 const {_} = useLingui() 21 const t = useTheme() 22 23 const {data: convo, isPending} = useMaybeConvoForUser(profile.did) 24 25 const onPress = React.useCallback(() => { 26 if (convo && !convo.lastMessage) { 27 logEvent('chat:create', {logContext: 'ProfileHeader'}) 28 } 29 logEvent('chat:open', {logContext: 'ProfileHeader'}) 30 }, [convo]) 31 32 if (isPending) { 33 // show pending state based on declaration 34 if (canBeMessaged(profile)) { 35 return ( 36 <View 37 testID="dmBtnLoading" 38 aria-hidden={true} 39 style={[ 40 a.justify_center, 41 a.align_center, 42 t.atoms.bg_contrast_25, 43 a.rounded_full, 44 {width: 34, height: 34}, 45 ]}> 46 <Message style={[t.atoms.text, {opacity: 0.3}]} size="md" /> 47 </View> 48 ) 49 } else { 50 return null 51 } 52 } 53 54 if (convo) { 55 return ( 56 <Link 57 testID="dmBtn" 58 size="small" 59 color="secondary" 60 variant="solid" 61 shape="round" 62 label={_(msg`Message ${profile.handle}`)} 63 to={`/messages/${convo.id}`} 64 style={[a.justify_center]} 65 onPress={onPress}> 66 <ButtonIcon icon={Message} size="md" /> 67 </Link> 68 ) 69 } else { 70 return null 71 } 72}