Changeset View
Changeset View
Standalone View
Standalone View
web/settings/relationship/add-users-list.react.js
Show First 20 Lines • Show All 84 Lines • ▼ Show 20 Lines | const mergedUserInfos = React.useMemo(() => { | ||||
for (const userInfo of serverSearchResults) { | for (const userInfo of serverSearchResults) { | ||||
mergedInfos[userInfo.id] = userInfo; | mergedInfos[userInfo.id] = userInfo; | ||||
} | } | ||||
const userStoreUserIDs = searchTextPresent | const userStoreUserIDs = searchTextPresent | ||||
? userStoreSearchResults | ? userStoreSearchResults | ||||
: Object.keys(userInfos); | : Object.keys(userInfos); | ||||
for (const id of userStoreUserIDs) { | for (const id of userStoreUserIDs) { | ||||
const { username, avatar, relationshipStatus } = userInfos[id]; | const { username, relationshipStatus } = userInfos[id]; | ||||
if (username) { | if (username) { | ||||
mergedInfos[id] = { id, username, avatar, relationshipStatus }; | mergedInfos[id] = { id, username, relationshipStatus }; | ||||
} | } | ||||
} | } | ||||
return mergedInfos; | return mergedInfos; | ||||
}, [ | }, [ | ||||
searchTextPresent, | searchTextPresent, | ||||
serverSearchResults, | serverSearchResults, | ||||
userInfos, | userInfos, | ||||
Show All 15 Lines | function AddUsersList(props: Props): React.Node { | ||||
const [pendingUsersToAdd, setPendingUsersToAdd] = React.useState< | const [pendingUsersToAdd, setPendingUsersToAdd] = React.useState< | ||||
$ReadOnlyArray<GlobalAccountUserInfo>, | $ReadOnlyArray<GlobalAccountUserInfo>, | ||||
>([]); | >([]); | ||||
const selectUser = React.useCallback( | const selectUser = React.useCallback( | ||||
(userID: string) => { | (userID: string) => { | ||||
setPendingUsersToAdd(pendingUsers => { | setPendingUsersToAdd(pendingUsers => { | ||||
const username = mergedUserInfos[userID]?.username; | const username = mergedUserInfos[userID]?.username; | ||||
const avatar = mergedUserInfos[userID]?.avatar; | |||||
if (!username || pendingUsers.some(user => user.id === userID)) { | if (!username || pendingUsers.some(user => user.id === userID)) { | ||||
return pendingUsers; | return pendingUsers; | ||||
} | } | ||||
const newPendingUser = { | const newPendingUser = { | ||||
id: userID, | id: userID, | ||||
username, | username, | ||||
avatar, | |||||
}; | }; | ||||
let targetIndex = 0; | let targetIndex = 0; | ||||
while ( | while ( | ||||
targetIndex < pendingUsers.length && | targetIndex < pendingUsers.length && | ||||
newPendingUser.username.localeCompare( | newPendingUser.username.localeCompare( | ||||
pendingUsers[targetIndex].username, | pendingUsers[targetIndex].username, | ||||
) > 0 | ) > 0 | ||||
) { | ) { | ||||
▲ Show 20 Lines • Show All 118 Lines • Show Last 20 Lines |