Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3494074
D8056.id27403.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D8056.id27403.diff
View Options
diff --git a/native/community-creation/community-creation-members.react.js b/native/community-creation/community-creation-members.react.js
--- a/native/community-creation/community-creation-members.react.js
+++ b/native/community-creation/community-creation-members.react.js
@@ -2,13 +2,32 @@
import * as React from 'react';
+import {
+ userInfoSelectorForPotentialMembers,
+ userSearchIndexForPotentialMembers,
+} from 'lib/selectors/user-selectors.js';
+import { getPotentialMemberItems } from 'lib/shared/search-utils.js';
+import { threadTypes } from 'lib/types/thread-types-enum.js';
+import type { AccountUserInfo } from 'lib/types/user-types.js';
+
import CommunityCreationKeyserverLabel from './community-creation-keyserver-label.react.js';
import type { CommunityCreationNavigationProp } from './community-creation-navigator.react.js';
import RegistrationContainer from '../account/registration/registration-container.react.js';
import RegistrationContentContainer from '../account/registration/registration-content-container.react.js';
+import { createTagInput } from '../components/tag-input.react.js';
+import UserList from '../components/user-list.react.js';
import type { NavigationRoute } from '../navigation/route-names.js';
+import { useSelector } from '../redux/redux-utils.js';
import { useStyles } from '../themes/colors.js';
+const TagInput = createTagInput<AccountUserInfo>();
+const tagInputProps = {
+ placeholder: 'username',
+ autoFocus: true,
+ returnKeyType: 'go',
+};
+const tagDataLabelExtractor = (userInfo: AccountUserInfo) => userInfo.username;
+
type Props = {
+navigation: CommunityCreationNavigationProp<'CommunityCreationMembers'>,
+route: NavigationRoute<'CommunityCreationMembers'>,
@@ -18,10 +37,63 @@
function CommunityCreationMembers(props: Props): React.Node {
const styles = useStyles(unboundStyles);
+ const otherUserInfos = useSelector(userInfoSelectorForPotentialMembers);
+ const userSearchIndex = useSelector(userSearchIndexForPotentialMembers);
+
+ const [usernameInputText, setUsernameInputText] = React.useState<string>('');
+ const [selectedUsers, setSelectedUsers] = React.useState<
+ $ReadOnlyArray<AccountUserInfo>,
+ >([]);
+
+ const selectedUserIDs = React.useMemo(
+ () => selectedUsers.map(userInfo => userInfo.id),
+ [selectedUsers],
+ );
+
+ const userSearchResults = React.useMemo(
+ () =>
+ getPotentialMemberItems(
+ usernameInputText,
+ otherUserInfos,
+ userSearchIndex,
+ selectedUserIDs,
+ null,
+ null,
+ threadTypes.COMMUNITY_ROOT,
+ ),
+ [otherUserInfos, selectedUserIDs, userSearchIndex, usernameInputText],
+ );
+
+ const onSelectUser = React.useCallback(
+ userID => {
+ if (selectedUserIDs.some(existingUserID => userID === existingUserID)) {
+ return;
+ }
+ setSelectedUsers(oldUserInfoInputArray => [
+ ...oldUserInfoInputArray,
+ otherUserInfos[userID],
+ ]);
+ setUsernameInputText('');
+ },
+ [otherUserInfos, selectedUserIDs],
+ );
+
+ const tagInputRef = React.useRef();
+
return (
<RegistrationContainer>
<RegistrationContentContainer style={styles.containerPaddingOverride}>
<CommunityCreationKeyserverLabel />
+ <TagInput
+ value={selectedUsers}
+ onChange={setSelectedUsers}
+ text={usernameInputText}
+ onChangeText={setUsernameInputText}
+ labelExtractor={tagDataLabelExtractor}
+ inputProps={tagInputProps}
+ ref={tagInputRef}
+ />
+ <UserList userInfos={userSearchResults} onSelect={onSelectUser} />
</RegistrationContentContainer>
</RegistrationContainer>
);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Dec 20, 4:18 AM (21 h, 7 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2680383
Default Alt Text
D8056.id27403.diff (3 KB)
Attached To
Mode
D8056: [native] Barebones user selection in `CommunityCreationMembers`
Attached
Detach File
Event Timeline
Log In to Comment