MCPcopy Create free account
hub / github.com/Linen-dev/linen.dev / ShowUsers

Function ShowUsers

apps/web/ui/ShowUsers/index.tsx:11–83  ·  view source on GitHub ↗
({
  communityId,
  setUsers,
  users,
  removeUser,
  currentUser,
  api,
  focus = true,
}: {
  communityId: string;
  users: SerializedUser[];
  setUsers: React.Dispatch<React.SetStateAction<SerializedUser[]>>;
  removeUser(user: SerializedUser): void;
  currentUser: SerializedUser | null;
  api: ApiClient;
  focus?: boolean | true;
})

Source from the content-addressed store, hash-verified

9import unique from 'lodash.uniq';
10
11export default function ShowUsers({
12 communityId,
13 setUsers,
14 users,
15 removeUser,
16 currentUser,
17 api,
18 focus = true,
19}: {
20 communityId: string;
21 users: SerializedUser[];
22 setUsers: React.Dispatch<React.SetStateAction<SerializedUser[]>>;
23 removeUser(user: SerializedUser): void;
24 currentUser: SerializedUser | null;
25 api: ApiClient;
26 focus?: boolean | true;
27}) {
28 const ref = useRef(null);
29 const [query, setQuery] = useState<SerializedUser[]>([]);
30 const [val, setVal] = useState<string>();
31
32 return (
33 <>
34 <Label htmlFor="userId">Add member</Label>
35 <TextInput
36 autoFocus={focus}
37 inputRef={ref}
38 id="userId"
39 name="userId"
40 value={val}
41 autoComplete="off"
42 onInput={(e: any) => {
43 setVal(e.target.value);
44 api.fetchMentions(e.target.value, communityId).then(setQuery);
45 }}
46 />
47 <Suggestions
48 className={styles.suggestions}
49 users={query}
50 onSelect={(user: SerializedUser | null) => {
51 if (user) {
52 setUsers(unique([...users, user]));
53 setVal('');
54 (ref.current as any).focus();
55 setQuery([]);
56 }
57 }}
58 />
59 <span className={styles.textXs}>Type for search users</span>
60
61 {users.length > 0 && (
62 <>
63 <Label htmlFor="members" className={styles.pt4}>
64 Members
65 </Label>
66 <div className={styles.usersWrapper}>
67 {users.map((user) => {
68 const props =

Callers

nothing calls this directly

Calls 4

setQueryFunction · 0.85
mapMethod · 0.80
fetchMentionsMethod · 0.65
removeUserFunction · 0.50

Tested by

no test coverage detected