mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
at verify-code 1.8 kB view raw
1import React from 'react' 2import {StyleProp, TextStyle, View} from 'react-native' 3import {AppBskyActorDefs} from '@atproto/api' 4import {msg} from '@lingui/macro' 5import {useLingui} from '@lingui/react' 6 7import {Shadow} from '#/state/cache/types' 8import {useProfileFollowMutationQueue} from '#/state/queries/profile' 9import {Button, ButtonType} from '../util/forms/Button' 10import * as Toast from '../util/Toast' 11 12export function FollowButton({ 13 unfollowedType = 'inverted', 14 followedType = 'default', 15 profile, 16 labelStyle, 17 logContext, 18}: { 19 unfollowedType?: ButtonType 20 followedType?: ButtonType 21 profile: Shadow<AppBskyActorDefs.ProfileViewBasic> 22 labelStyle?: StyleProp<TextStyle> 23 logContext: 'ProfileCard' | 'StarterPackProfilesList' 24}) { 25 const [queueFollow, queueUnfollow] = useProfileFollowMutationQueue( 26 profile, 27 logContext, 28 ) 29 const {_} = useLingui() 30 31 const onPressFollow = async () => { 32 try { 33 await queueFollow() 34 } catch (e: any) { 35 if (e?.name !== 'AbortError') { 36 Toast.show(_(msg`An issue occurred, please try again.`), 'xmark') 37 } 38 } 39 } 40 41 const onPressUnfollow = async () => { 42 try { 43 await queueUnfollow() 44 } catch (e: any) { 45 if (e?.name !== 'AbortError') { 46 Toast.show(_(msg`An issue occurred, please try again.`), 'xmark') 47 } 48 } 49 } 50 51 if (!profile.viewer) { 52 return <View /> 53 } 54 55 if (profile.viewer.following) { 56 return ( 57 <Button 58 type={followedType} 59 labelStyle={labelStyle} 60 onPress={onPressUnfollow} 61 label={_(msg({message: 'Unfollow', context: 'action'}))} 62 /> 63 ) 64 } else { 65 return ( 66 <Button 67 type={unfollowedType} 68 labelStyle={labelStyle} 69 onPress={onPressFollow} 70 label={_(msg({message: 'Follow', context: 'action'}))} 71 /> 72 ) 73 } 74}