diff --git a/native/components/relationship-button.react.js b/native/components/relationship-button.react.js --- a/native/components/relationship-button.react.js +++ b/native/components/relationship-button.react.js @@ -2,11 +2,13 @@ import Icon from '@expo/vector-icons/FontAwesome5.js'; import * as React from 'react'; -import { Text } from 'react-native'; +import { Text, ActivityIndicator } from 'react-native'; import Button from './button.react.js'; import { useStyles, useColors } from '../themes/colors.js'; +type ButtonSize = 'S'; + type RelationshipButtonType = | 'add' | 'withdraw' @@ -18,10 +20,12 @@ type Props = { +type: RelationshipButtonType, +onPress: () => mixed, + +isLoading: boolean, + +size?: ButtonSize, }; function RelationshipButton(props: Props): React.Node { - const { type, onPress } = props; + const { type, onPress, isLoading, size } = props; const styles = useStyles(unboundStyles); const colors = useColors(); @@ -29,6 +33,10 @@ const buttonStyle = React.useMemo(() => { const result = [styles.buttonContainer]; + if (size === 'S') { + result.push(styles.smallButtonContainer); + } + if (type === 'add' || type === 'accept' || type === 'unblock') { result.push(styles.greenButton); } else { @@ -36,35 +44,72 @@ } return result; - }, [styles.buttonContainer, styles.greenButton, styles.redButton, type]); + }, [ + size, + styles.buttonContainer, + styles.greenButton, + styles.redButton, + styles.smallButtonContainer, + type, + ]); + + const buttonTextStyle = React.useMemo(() => { + const result = [styles.buttonText]; + + if (size === 'S') { + result.push(styles.smallButtonText); + } + + return result; + }, [size, styles.buttonText, styles.smallButtonText]); - let buttonText = 'Add Friend'; + let buttonText = 'Add friend'; let icon = 'user-plus'; if (type === 'withdraw') { - buttonText = 'Withdraw Friend Request'; + buttonText = 'Withdraw friend request'; icon = 'user-minus'; } else if (type === 'accept') { - buttonText = 'Accept'; + buttonText = 'Accept friend request'; } else if (type === 'reject') { - buttonText = 'Reject'; + buttonText = 'Reject friend request'; icon = 'user-minus'; } else if (type === 'block') { - buttonText = 'Block User'; + buttonText = 'Block user'; icon = 'user-shield'; } else if (type === 'unblock') { - buttonText = 'Unblock User'; + buttonText = 'Unblock user'; icon = 'user-shield'; } + const buttonContent = React.useMemo(() => { + if (isLoading) { + return ; + } + + return ( + <> + + {buttonText} + + ); + }, [ + buttonText, + buttonTextStyle, + colors.floatingButtonLabel, + colors.whiteText, + icon, + isLoading, + styles.buttonIcon, + ]); + return ( - ); } @@ -74,7 +119,7 @@ flexDirection: 'row', justifyContent: 'center', alignItems: 'center', - paddingVertical: 8, + paddingVertical: 10, borderRadius: 8, }, buttonIcon: { @@ -89,6 +134,12 @@ redButton: { backgroundColor: 'vibrantRedButton', }, + smallButtonContainer: { + paddingVertical: 8, + }, + smallButtonText: { + fontSize: 11, + }, }; export default RelationshipButton; diff --git a/native/user-profile/user-profile-relationship-button.react.js b/native/user-profile/user-profile-relationship-button.react.js --- a/native/user-profile/user-profile-relationship-button.react.js +++ b/native/user-profile/user-profile-relationship-button.react.js @@ -39,6 +39,7 @@ const { otherUserInfo, callbacks: { friendUser, unfriendUser }, + loaders: { isLoadingFriendUser, isLoadingUnfriendUser }, } = useRelationshipPrompt( threadInfo, onErrorCallback, @@ -91,10 +92,20 @@ - + - + @@ -106,18 +117,28 @@ ) { return ( - + ); } return ( - + ); }, [ friendUser, + isLoadingFriendUser, + isLoadingUnfriendUser, otherUserInfo, styles.acceptFriendRequestButtonContainer, styles.incomingFriendRequestButtonsContainer, @@ -134,6 +155,7 @@ const unboundStyles = { singleButtonContainer: { marginTop: 16, + height: 38, }, incomingFriendRequestContainer: { marginTop: 24, @@ -144,6 +166,7 @@ incomingFriendRequestButtonsContainer: { flexDirection: 'row', marginTop: 8, + height: 32, }, acceptFriendRequestButtonContainer: { flex: 1,