* 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
41 lines
1.2 KiB
TypeScript
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,
|
|
};
|
|
};
|