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 @@ -82,16 +82,54 @@ .sort((user1, user2) => user1.username.localeCompare(user2.username)); }, [excludedStatuses, mergedUserInfos]); + const [pendingUsersToAdd, setPendingUsersToAdd] = React.useState< + $ReadOnlyArray, + >([]); + const selectUser = React.useCallback( + (userID: string) => { + setPendingUsersToAdd(pendingUsers => { + const username = mergedUserInfos[userID]?.username; + if (!username) { + return pendingUsers; + } + + for (const pendingUser of pendingUsers) { + if (pendingUser.id === userID) { + return pendingUsers; + } + } + + return [ + ...pendingUsers, + { + id: userID, + username, + }, + ].sort((user1, user2) => user1.username.localeCompare(user2.username)); + }); + }, + [mergedUserInfos], + ); + const pendingUserIDs = React.useMemo( + () => new Set(pendingUsersToAdd.map(userInfo => userInfo.id)), + [pendingUsersToAdd], + ); + + const filteredUsers = React.useMemo( + () => sortedUsers.filter(userInfo => !pendingUserIDs.has(userInfo.id)), + [pendingUserIDs, sortedUsers], + ); + const userRows = React.useMemo( () => - sortedUsers.map(userInfo => ( + filteredUsers.map(userInfo => ( {}} + selectUser={selectUser} /> )), - [sortedUsers], + [filteredUsers, selectUser], ); return
{userRows}
; }