[ESLint rule]: recoil value and setter should be named after their at… (#1402)
* Override unwanted changes Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: Toledodev <rafael.toledo@engenharia.ufjf.br> Co-authored-by: Rafael Toledo <87545086+Toledodev@users.noreply.github.com> * Fix the tests Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: Toledodev <rafael.toledo@engenharia.ufjf.br> Co-authored-by: Rafael Toledo <87545086+Toledodev@users.noreply.github.com> --------- Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: Toledodev <rafael.toledo@engenharia.ufjf.br> Co-authored-by: Rafael Toledo <87545086+Toledodev@users.noreply.github.com> Co-authored-by: Charles Bochet <charlesBochet@users.noreply.github.com>
This commit is contained in:
@ -17,12 +17,11 @@ export function useEntitySelectScroll<
|
||||
entities: CustomEntityForSelect[];
|
||||
containerRef: React.RefObject<HTMLDivElement>;
|
||||
}) {
|
||||
const [hoveredIndex, setHoveredIndex] = useRecoilScopedState(
|
||||
relationPickerHoverIndexScopedState,
|
||||
);
|
||||
const [relationPickerHoverIndex, setRelationPickerHoverIndex] =
|
||||
useRecoilScopedState(relationPickerHoverIndexScopedState);
|
||||
|
||||
function resetScroll() {
|
||||
setHoveredIndex(0);
|
||||
setRelationPickerHoverIndex(0);
|
||||
|
||||
const currentHoveredRef = containerRef.current?.children[0] as HTMLElement;
|
||||
|
||||
@ -40,12 +39,12 @@ export function useEntitySelectScroll<
|
||||
useScopedHotkeys(
|
||||
Key.ArrowUp,
|
||||
() => {
|
||||
setHoveredIndex((prevSelectedIndex) =>
|
||||
setRelationPickerHoverIndex((prevSelectedIndex) =>
|
||||
Math.max(prevSelectedIndex - 1, 0),
|
||||
);
|
||||
|
||||
const currentHoveredRef = containerRef.current?.children[
|
||||
hoveredIndex
|
||||
relationPickerHoverIndex
|
||||
] as HTMLElement;
|
||||
|
||||
if (currentHoveredRef) {
|
||||
@ -61,18 +60,18 @@ export function useEntitySelectScroll<
|
||||
}
|
||||
},
|
||||
RelationPickerHotkeyScope.RelationPicker,
|
||||
[setHoveredIndex, entities],
|
||||
[setRelationPickerHoverIndex, entities],
|
||||
);
|
||||
|
||||
useScopedHotkeys(
|
||||
Key.ArrowDown,
|
||||
() => {
|
||||
setHoveredIndex((prevSelectedIndex) =>
|
||||
setRelationPickerHoverIndex((prevSelectedIndex) =>
|
||||
Math.min(prevSelectedIndex + 1, (entities?.length ?? 0) - 1),
|
||||
);
|
||||
|
||||
const currentHoveredRef = containerRef.current?.children[
|
||||
hoveredIndex
|
||||
relationPickerHoverIndex
|
||||
] as HTMLElement;
|
||||
|
||||
if (currentHoveredRef) {
|
||||
@ -88,11 +87,11 @@ export function useEntitySelectScroll<
|
||||
}
|
||||
},
|
||||
RelationPickerHotkeyScope.RelationPicker,
|
||||
[setHoveredIndex, entities],
|
||||
[setRelationPickerHoverIndex, entities],
|
||||
);
|
||||
|
||||
return {
|
||||
hoveredIndex,
|
||||
hoveredIndex: relationPickerHoverIndex,
|
||||
resetScroll,
|
||||
};
|
||||
}
|
||||
|
||||
@ -7,31 +7,34 @@ import { relationPickerHoverIndexScopedState } from '../states/relationPickerHov
|
||||
import { relationPickerSearchFilterScopedState } from '../states/relationPickerSearchFilterScopedState';
|
||||
|
||||
export function useEntitySelectSearch() {
|
||||
const [, setHoveredIndex] = useRecoilScopedState(
|
||||
const [, setRelationPickerHoverIndex] = useRecoilScopedState(
|
||||
relationPickerHoverIndexScopedState,
|
||||
);
|
||||
|
||||
const [searchFilter, setSearchFilter] = useRecoilScopedState(
|
||||
relationPickerSearchFilterScopedState,
|
||||
);
|
||||
const [relationPickerSearchFilter, setRelationPickerSearchFilter] =
|
||||
useRecoilScopedState(relationPickerSearchFilterScopedState);
|
||||
|
||||
const debouncedSetSearchFilter = debounce(setSearchFilter, 100, {
|
||||
leading: true,
|
||||
});
|
||||
const debouncedSetSearchFilter = debounce(
|
||||
setRelationPickerSearchFilter,
|
||||
100,
|
||||
{
|
||||
leading: true,
|
||||
},
|
||||
);
|
||||
|
||||
function handleSearchFilterChange(
|
||||
event: React.ChangeEvent<HTMLInputElement>,
|
||||
) {
|
||||
debouncedSetSearchFilter(event.currentTarget.value);
|
||||
setHoveredIndex(0);
|
||||
setRelationPickerHoverIndex(0);
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
setSearchFilter('');
|
||||
}, [setSearchFilter]);
|
||||
setRelationPickerSearchFilter('');
|
||||
}, [setRelationPickerSearchFilter]);
|
||||
|
||||
return {
|
||||
searchFilter,
|
||||
searchFilter: relationPickerSearchFilter,
|
||||
handleSearchFilterChange,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user