Refactor hotkyes in its own lib folder (#660)

* Refactor hotkyes in its own lib folder

* Lint

* Fix PR comments

* rename hotkeysScope into hotkeyScope
This commit is contained in:
Charles Bochet
2023-07-14 12:27:26 -07:00
committed by GitHub
parent 7bcea343e2
commit e93a96b3b1
71 changed files with 398 additions and 386 deletions

View File

@ -10,11 +10,12 @@ import styled from '@emotion/styled';
import { IconAlertCircle } from '@tabler/icons-react';
import { Key } from 'ts-key-enum';
import { usePreviousHotkeysScope } from '@/hotkeys/hooks/internal/usePreviousHotkeysScope';
import { useScopedHotkeys } from '@/hotkeys/hooks/useScopedHotkeys';
import { InternalHotkeysScope } from '@/hotkeys/types/internal/InternalHotkeysScope';
import { usePreviousHotkeyScope } from '@/lib/hotkeys/hooks/usePreviousHotkeyScope';
import { useScopedHotkeys } from '@/lib/hotkeys/hooks/useScopedHotkeys';
import { IconEye, IconEyeOff } from '@/ui/icons/index';
import { InputHotkeyScope } from './types/InputHotkeyScope';
type OwnProps = Omit<InputHTMLAttributes<HTMLInputElement>, 'onChange'> & {
label?: string;
onChange?: (text: string) => void;
@ -110,18 +111,18 @@ export function TextInput({
const inputRef = useRef<HTMLInputElement>(null);
const {
goBackToPreviousHotkeysScope,
setHotkeysScopeAndMemorizePreviousScope,
} = usePreviousHotkeysScope();
goBackToPreviousHotkeyScope,
setHotkeyScopeAndMemorizePreviousScope,
} = usePreviousHotkeyScope();
const handleFocus: FocusEventHandler<HTMLInputElement> = (e) => {
onFocus?.(e);
setHotkeysScopeAndMemorizePreviousScope(InternalHotkeysScope.TextInput);
setHotkeyScopeAndMemorizePreviousScope(InputHotkeyScope.TextInput);
};
const handleBlur: FocusEventHandler<HTMLInputElement> = (e) => {
onBlur?.(e);
goBackToPreviousHotkeysScope();
goBackToPreviousHotkeyScope();
};
useScopedHotkeys(
@ -129,7 +130,7 @@ export function TextInput({
() => {
inputRef.current?.blur();
},
InternalHotkeysScope.TextInput,
InputHotkeyScope.TextInput,
);
const [passwordVisible, setPasswordVisible] = useState(false);