mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
at next/base 143 lines 4.0 kB view raw
1import React from 'react' 2import {View} from 'react-native' 3import {AppBskyActorDefs, ModerationDecision} from '@atproto/api' 4import {msg} from '@lingui/macro' 5import {useLingui} from '@lingui/react' 6import {useNavigation} from '@react-navigation/native' 7 8import {NavigationProp} from '#/lib/routes/types' 9import {sanitizeDisplayName} from '#/lib/strings/display-names' 10import {useProfileShadow} from '#/state/cache/profile-shadow' 11import {useSession} from '#/state/session' 12import { 13 DropdownItem, 14 NativeDropdown, 15} from '#/view/com/util/forms/NativeDropdown' 16import * as Toast from '#/view/com/util/Toast' 17import {atoms as a, select, useTheme} from '#/alf' 18import {Button} from '#/components/Button' 19import {useFollowMethods} from '#/components/hooks/useFollowMethods' 20import {PlusSmall_Stroke2_Corner0_Rounded as Plus} from '#/components/icons/Plus' 21 22export function AviFollowButton({ 23 author, 24 moderation, 25 children, 26}: { 27 author: AppBskyActorDefs.ProfileViewBasic 28 moderation: ModerationDecision 29 children: React.ReactNode 30}) { 31 const {_} = useLingui() 32 const t = useTheme() 33 const profile = useProfileShadow(author) 34 const {follow} = useFollowMethods({ 35 profile: profile, 36 logContext: 'AvatarButton', 37 }) 38 const {currentAccount, hasSession} = useSession() 39 const navigation = useNavigation<NavigationProp>() 40 41 const name = sanitizeDisplayName( 42 profile.displayName || profile.handle, 43 moderation.ui('displayName'), 44 ) 45 const isFollowing = 46 profile.viewer?.following || profile.did === currentAccount?.did 47 48 function onPress() { 49 follow() 50 Toast.show(_(msg`Following ${name}`)) 51 } 52 53 const items: DropdownItem[] = [ 54 { 55 label: _(msg`View profile`), 56 onPress: () => { 57 navigation.navigate('Profile', {name: profile.did}) 58 }, 59 icon: { 60 ios: { 61 name: 'arrow.up.right.square', 62 }, 63 android: '', 64 web: ['far', 'arrow-up-right-from-square'], 65 }, 66 }, 67 { 68 label: _(msg`Follow ${name}`), 69 onPress: onPress, 70 icon: { 71 ios: { 72 name: 'person.badge.plus', 73 }, 74 android: '', 75 web: ['far', 'user-plus'], 76 }, 77 }, 78 ] 79 80 return hasSession ? ( 81 <View style={a.relative}> 82 {children} 83 84 {!isFollowing && ( 85 <Button 86 label={_(msg`Open ${name} profile shortcut menu`)} 87 style={[ 88 a.rounded_full, 89 a.absolute, 90 { 91 bottom: -7, 92 right: -7, 93 }, 94 ]}> 95 <NativeDropdown items={items}> 96 <View 97 style={[ 98 { 99 // An asymmetric hit slop 100 // to prioritize bottom right taps. 101 paddingTop: 2, 102 paddingLeft: 2, 103 paddingBottom: 6, 104 paddingRight: 6, 105 }, 106 a.align_center, 107 a.justify_center, 108 a.rounded_full, 109 ]}> 110 <View 111 style={[ 112 a.rounded_full, 113 a.align_center, 114 select(t.name, { 115 light: t.atoms.bg_contrast_100, 116 dim: t.atoms.bg_contrast_100, 117 dark: t.atoms.bg_contrast_200, 118 }), 119 { 120 borderWidth: 1, 121 borderColor: t.atoms.bg.backgroundColor, 122 }, 123 ]}> 124 <Plus 125 size="sm" 126 fill={ 127 select(t.name, { 128 light: t.atoms.bg_contrast_600, 129 dim: t.atoms.bg_contrast_500, 130 dark: t.atoms.bg_contrast_600, 131 }).backgroundColor 132 } 133 /> 134 </View> 135 </View> 136 </NativeDropdown> 137 </Button> 138 )} 139 </View> 140 ) : ( 141 children 142 ) 143}