Files
twenty/front/src/modules/ui/relation-picker/hooks/useEntitySelectSearch.ts
Charles Bochet 6ced8434bd Uniformize folder structure (#693)
* Uniformize folder structure

* Fix icons

* Fix icons

* Fix tests

* Fix tests
2023-07-16 14:29:28 -07:00

33 lines
925 B
TypeScript

import debounce from 'lodash.debounce';
import { useRecoilScopedState } from '@/ui/recoil-scope/hooks/useRecoilScopedState';
import { relationPickerHoverIndexScopedState } from '../states/relationPickerHoverIndexScopedState';
import { relationPickerSearchFilterScopedState } from '../states/relationPickerSearchFilterScopedState';
export function useEntitySelectSearch() {
const [, setHoveredIndex] = useRecoilScopedState(
relationPickerHoverIndexScopedState,
);
const [searchFilter, setSearchFilter] = useRecoilScopedState(
relationPickerSearchFilterScopedState,
);
const debouncedSetSearchFilter = debounce(setSearchFilter, 100, {
leading: true,
});
function handleSearchFilterChange(
event: React.ChangeEvent<HTMLInputElement>,
) {
debouncedSetSearchFilter(event.currentTarget.value);
setHoveredIndex(0);
}
return {
searchFilter,
handleSearchFilterChange,
};
}