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 @@ -14,7 +14,6 @@ import AddUsersListItem from './add-users-list-item.react.js'; import css from './add-users-list.css'; -import Label from '../../components/label.react.js'; import { useSelector } from '../../redux/redux-utils.js'; type Props = { @@ -84,80 +83,37 @@ ); const [pendingUsersToAdd, setPendingUsersToAdd] = React.useState< - $ReadOnlyArray, - >([]); - const selectUser = React.useCallback( + $ReadOnlySet, + >(new Set()); + + const toggleUser = React.useCallback( (userID: string) => { setPendingUsersToAdd(pendingUsers => { - const username = mergedUserInfos[userID]?.username; - if (!username || pendingUsers.some(user => user.id === userID)) { - return pendingUsers; - } + const newPendingUsers = new Set(pendingUsers); - const newPendingUser = { - id: userID, - username, - }; - let targetIndex = 0; - while ( - targetIndex < pendingUsers.length && - newPendingUser.username.localeCompare( - pendingUsers[targetIndex].username, - ) > 0 - ) { - targetIndex++; + if (!newPendingUsers.delete(userID)) { + newPendingUsers.add(userID); } - return [ - ...pendingUsers.slice(0, targetIndex), - newPendingUser, - ...pendingUsers.slice(targetIndex), - ]; + + return newPendingUsers; }); }, - [mergedUserInfos], - ); - const deselectUser = React.useCallback( - (userID: string) => - setPendingUsersToAdd(pendingUsers => - pendingUsers.filter(userInfo => userInfo.id !== userID), - ), - [], - ); - const pendingUserIDs = React.useMemo( - () => new Set(pendingUsersToAdd.map(userInfo => userInfo.id)), - [pendingUsersToAdd], + [setPendingUsersToAdd], ); - const pendingUsersWithENSNames = useENSNames(pendingUsersToAdd); - const userTags = React.useMemo(() => { - if (pendingUsersWithENSNames.length === 0) { - return null; - } - const tags = pendingUsersWithENSNames.map(userInfo => ( - - )); - return
{tags}
; - }, [deselectUser, pendingUsersWithENSNames]); - - const filteredUsers = React.useMemo( - () => sortedUsers.filter(userInfo => !pendingUserIDs.has(userInfo.id)), - [pendingUserIDs, sortedUsers], - ); - const filteredUsersWithENSNames = useENSNames(filteredUsers); + const sortedUsersWithENSNames = useENSNames(sortedUsers); const userRows = React.useMemo( () => - filteredUsersWithENSNames.map(userInfo => ( + sortedUsersWithENSNames.map(userInfo => ( )), - [filteredUsersWithENSNames, selectUser], + [sortedUsersWithENSNames, toggleUser, pendingUsersToAdd], ); let errors; @@ -167,7 +123,6 @@ return (
- {userTags}
{userRows}
{errors}