diff --git a/web/settings/relationship/add-users-list.react.js b/web/settings/relationship/add-users-list.react.js --- a/web/settings/relationship/add-users-list.react.js +++ b/web/settings/relationship/add-users-list.react.js @@ -16,7 +16,6 @@ function AddUsersList(props: Props): React.Node { const { searchText } = props; - // eslint-disable-next-line no-unused-vars const [userStoreSearchResults, setUserStoreSearchResults] = React.useState< $ReadOnlySet, >(new Set()); @@ -27,7 +26,6 @@ ); }, [searchText, userStoreSearchIndex]); - // eslint-disable-next-line no-unused-vars const [serverSearchResults, setServerSearchResults] = React.useState< $ReadOnlyArray, >([]); @@ -43,6 +41,34 @@ })(); }, [callSearchUsers, searchText]); + const searchTextPresent = !!searchText; + const userInfos = useSelector(state => state.userStore.userInfos); + // eslint-disable-next-line no-unused-vars + const mergedUserInfos = React.useMemo(() => { + const mergedInfos = {}; + + for (const userInfo of serverSearchResults) { + mergedInfos[userInfo.id] = userInfo; + } + + const userStoreUserIDs = searchTextPresent + ? userStoreSearchResults + : Object.keys(userInfos); + for (const id of userStoreUserIDs) { + const { username, relationshipStatus } = userInfos[id]; + if (username) { + mergedInfos[id] = { id, username, relationshipStatus }; + } + } + + return mergedInfos; + }, [ + searchTextPresent, + serverSearchResults, + userInfos, + userStoreSearchResults, + ]); + return null; }