diff --git a/native/profile/relationship-list.react.js b/native/profile/relationship-list.react.js --- a/native/profile/relationship-list.react.js +++ b/native/profile/relationship-list.react.js @@ -9,6 +9,7 @@ import { useENSNames } from 'lib/hooks/ens-cache.js'; import { useUpdateRelationships } from 'lib/hooks/relationship-hooks.js'; import { registerFetchKey } from 'lib/reducers/loading-reducer.js'; +import { createLoadingStatusSelector } from 'lib/selectors/loading-selectors.js'; import { useUserSearchIndex } from 'lib/selectors/nav-selectors.js'; import { userRelationshipsSelector } from 'lib/selectors/relationship-selectors.js'; import { useSearchUsers } from 'lib/shared/search-utils.js'; @@ -82,6 +83,10 @@ const tagDataLabelExtractor = (userInfo: GlobalAccountUserInfo) => userInfo.username; +const loadingStatusSelector = createLoadingStatusSelector( + updateRelationshipsActionTypes, +); + type Props = { +navigation: ProfileNavigationProp<'FriendList' | 'BlockList'>, +route: NavigationRoute<'FriendList' | 'BlockList'>, @@ -197,8 +202,11 @@ tagInputRef.current?.focus(); }, []); + const updateInProgress = React.useRef(false); + const updateRelationships = useUpdateRelationships(); const updateRelationshipsOnServer = React.useCallback(async () => { + updateInProgress.current = true; const action = { [FriendListRouteName]: relationshipActions.FRIEND, [BlockListRouteName]: relationshipActions.BLOCK, @@ -217,6 +225,8 @@ { cancelable: true, onDismiss: onUnknownErrorAlertAcknowledged }, ); throw e; + } finally { + updateInProgress.current = false; } }, [ routeName, @@ -228,7 +238,7 @@ const dispatchActionPromise = useDispatchActionPromise(); const noCurrentTags = currentTags.length === 0; const onPressAdd = React.useCallback(() => { - if (noCurrentTags) { + if (noCurrentTags || updateInProgress.current) { return; } void dispatchActionPromise( @@ -285,6 +295,7 @@ const { setOptions } = navigation; const prevNoCurrentTags = React.useRef(noCurrentTags); + const loadingStatus = useSelector(loadingStatusSelector); React.useEffect(() => { let setSaveButtonDisabled; if (!prevNoCurrentTags.current && noCurrentTags) { @@ -301,11 +312,15 @@ ), }); - }, [setOptions, noCurrentTags, onPressAdd]); + }, [setOptions, noCurrentTags, onPressAdd, loadingStatus]); const relationships = useSelector(userRelationshipsSelector); const viewerID = useSelector(