Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Add debouncing to add users search field. #20297

Merged
merged 2 commits into from
Feb 2, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions ee/client/audit/UserAutoCompleteMultiple.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useMemo, useState } from 'react';
import { AutoComplete, Box, Option, Options, Chip } from '@rocket.chat/fuselage';
import { useMutableCallback } from '@rocket.chat/fuselage-hooks';
import { useMutableCallback, useDebouncedValue } from '@rocket.chat/fuselage-hooks';

import UserAvatar from '../../../client/components/avatar/UserAvatar';
import { useEndpointData } from '../../../client/hooks/useEndpointData';
Expand All @@ -11,7 +11,8 @@ const Avatar = ({ value, ...props }) => <UserAvatar size={Options.AvatarSize} us

const UserAutoCompleteMultiple = React.memo((props) => {
const [filter, setFilter] = useState('');
const { value: data } = useEndpointData('users.autocomplete', useMemo(() => query(filter), [filter]));
const debouncedFilter = useDebouncedValue(filter, 1000);
const { value: data } = useEndpointData('users.autocomplete', useMemo(() => query(debouncedFilter), [debouncedFilter]));
const options = useMemo(() => (data && data.items.map((user) => ({ value: user.username, label: user.name }))) || [], [data]);
const onClickRemove = useMutableCallback((e) => {
e.stopPropagation();
Expand Down