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