diff --git a/native/chat/relationship-prompt.react.js b/native/chat/relationship-prompt.react.js --- a/native/chat/relationship-prompt.react.js +++ b/native/chat/relationship-prompt.react.js @@ -2,7 +2,7 @@ import Icon from '@expo/vector-icons/FontAwesome5.js'; import * as React from 'react'; -import { Text, View } from 'react-native'; +import { Text, View, ActivityIndicator } from 'react-native'; import { useRelationshipPrompt } from 'lib/hooks/relationship-prompt.js'; import type { ThreadInfo } from 'lib/types/minimally-encoded-thread-permissions-types.js'; @@ -10,10 +10,51 @@ import type { UserInfo } from 'lib/types/user-types.js'; import Button from '../components/button.react.js'; -import { useStyles } from '../themes/colors.js'; +import { useStyles, useColors } from '../themes/colors.js'; import { unknownErrorAlertDetails } from '../utils/alert-messages.js'; import Alert from '../utils/alert.js'; +type ButtonContentContainerProps = { + +children: React.Node, + +isLoading: boolean, +}; + +function ButtonContentContainer(props: ButtonContentContainerProps) { + const { children, isLoading } = props; + + const styles = useStyles(unboundStyles); + const colors = useColors(); + + const buttonContentContainerStyles = React.useMemo(() => { + const result = [styles.buttonContentContainer]; + + if (isLoading) { + result.push(styles.buttonLoading); + } + + return result; + }, [isLoading, styles.buttonContentContainer, styles.buttonLoading]); + + const loadingSpinner = React.useMemo( + () => + isLoading ? ( + + ) : null, + [colors.whiteText, isLoading, styles.loadingSpinner], + ); + + return ( + <> + {children} + {loadingSpinner} + + ); +} + type Props = { +pendingPersonalThreadUserInfo: ?UserInfo, +threadInfo: ThreadInfo, @@ -34,6 +75,12 @@ const { otherUserInfo, callbacks: { blockUser, unblockUser, friendUser, unfriendUser }, + loadingState: { + isLoadingBlockUser, + isLoadingUnblockUser, + isLoadingFriendUser, + isLoadingUnfriendUser, + }, } = useRelationshipPrompt( threadInfo, onErrorCallback, @@ -54,9 +101,15 @@ ) { return ( - ); @@ -73,9 +126,12 @@ ); @@ -90,16 +146,22 @@ ); @@ -113,9 +175,12 @@ ); @@ -126,13 +191,22 @@ - ); @@ -152,6 +226,7 @@ flex: 1, flexDirection: 'row', justifyContent: 'center', + alignItems: 'center', marginHorizontal: 5, }, greenButton: { @@ -160,6 +235,13 @@ redButton: { backgroundColor: 'vibrantRedButton', }, + buttonContentContainer: { + flexDirection: 'row', + alignItems: 'center', + }, + buttonLoading: { + opacity: 0, + }, buttonText: { fontSize: 11, color: 'white', @@ -167,6 +249,9 @@ textAlign: 'center', marginLeft: 5, }, + loadingSpinner: { + position: 'absolute', + }, }; export default RelationshipPrompt;