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,7 +2,7 @@ import Icon from '@expo/vector-icons/FontAwesome5.js'; import * as React from 'react'; -import { Text } from 'react-native'; +import { View, Text, ActivityIndicator } from 'react-native'; import Button from './button.react.js'; import { useStyles, useColors } from '../themes/colors.js'; @@ -18,10 +18,11 @@ type Props = { +type: RelationshipButtonType, +onPress: () => mixed, + +isLoading: boolean, }; function RelationshipButton(props: Props): React.Node { - const { type, onPress } = props; + const { type, onPress, isLoading } = props; const styles = useStyles(unboundStyles); const colors = useColors(); @@ -38,10 +39,20 @@ return result; }, [styles.buttonContainer, styles.greenButton, styles.redButton, type]); - let buttonText = 'Add Friend'; + const buttonContentContainerStyles = React.useMemo(() => { + const result = [styles.buttonContentContainer]; + + if (isLoading) { + result.push(styles.buttonLoading); + } + + return result; + }, [isLoading, styles.buttonContentContainer, styles.buttonLoading]); + + 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'; @@ -49,22 +60,37 @@ buttonText = 'Reject'; 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 loadingSpinner = React.useMemo( + () => + isLoading ? ( + + ) : null, + [colors.whiteText, isLoading, styles.loadingSpinner], + ); + return ( - ); } @@ -77,6 +103,13 @@ paddingVertical: 8, borderRadius: 8, }, + buttonContentContainer: { + flexDirection: 'row', + alignItems: 'center', + }, + buttonLoading: { + opacity: 0, + }, buttonIcon: { paddingRight: 8, }, @@ -89,6 +122,9 @@ redButton: { backgroundColor: 'vibrantRedButton', }, + loadingSpinner: { + position: 'absolute', + }, }; 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 }, + loadingState: { isLoadingFriendUser, isLoadingUnfriendUser }, } = useRelationshipPrompt( threadInfo, onErrorCallback, @@ -91,10 +92,18 @@ - + - + @@ -106,18 +115,28 @@ ) { return ( - + ); } return ( - + ); }, [ friendUser, + isLoadingFriendUser, + isLoadingUnfriendUser, otherUserInfo, styles.acceptFriendRequestButtonContainer, styles.incomingFriendRequestButtonsContainer,