Files
twenty_crm/front/src/modules/ui/input/relation-picker/hooks/useEntitySelectSearch.ts
bosiraphael 95a1cfeec3 2426 timebox refactor board with the new scope architecture (#2789)
* scoped states: wip

* scoped states: wip

* wip

* wip

* create boardFiltersScopedState and boardSortsScopedState

* wip

* reorganize hooks

* update hooks

* wip

* wip

* fix options dropdown

* clean unused selectors

* fields are working

* fix filter an sort

* fix entity count

* rename hooks

* rename states

* clean unused context

* fix recoil scope bug

* objectNameSingular instead of objectNamePlural
2023-12-05 12:15:20 +01:00

41 lines
1.2 KiB
TypeScript

import debounce from 'lodash.debounce';
import { useRecoilScopedState } from '@/ui/utilities/recoil-scope/hooks/useRecoilScopedState';
import { RelationPickerRecoilScopeContext } from '../states/recoil-scope-contexts/RelationPickerRecoilScopeContext';
import { relationPickerPreselectedIdScopedState } from '../states/relationPickerPreselectedIdScopedState';
import { relationPickerSearchFilterScopedState } from '../states/relationPickerSearchFilterScopedState';
export const useEntitySelectSearch = () => {
const [, setRelationPickerPreselectedId] = useRecoilScopedState(
relationPickerPreselectedIdScopedState,
RelationPickerRecoilScopeContext,
);
const [relationPickerSearchFilter, setRelationPickerSearchFilter] =
useRecoilScopedState(
relationPickerSearchFilterScopedState,
RelationPickerRecoilScopeContext,
);
const debouncedSetSearchFilter = debounce(
setRelationPickerSearchFilter,
100,
{
leading: true,
},
);
const handleSearchFilterChange = (
event: React.ChangeEvent<HTMLInputElement>,
) => {
debouncedSetSearchFilter(event.currentTarget.value);
setRelationPickerPreselectedId('');
};
return {
searchFilter: relationPickerSearchFilter,
handleSearchFilterChange,
};
};