mirror of
https://github.com/Sonny93/my-links.git
synced 2025-12-09 07:03:25 +00:00
feat: add a search modal using the database (wip)
This commit is contained in:
@@ -2,18 +2,27 @@ import KEYS from '#constants/keys';
|
||||
import { useHotkeys } from 'react-hotkeys-hook';
|
||||
import useGlobalHotkeys from '~/hooks/use_global_hotkeys';
|
||||
|
||||
type ShortcutOptions = { ignoreGlobalHotkeysStatus?: boolean };
|
||||
type ShortcutOptions = {
|
||||
enabled?: boolean;
|
||||
};
|
||||
|
||||
export default function useShortcut(
|
||||
key: keyof typeof KEYS,
|
||||
cb: () => void,
|
||||
options: ShortcutOptions = {
|
||||
ignoreGlobalHotkeysStatus: false,
|
||||
{ enabled }: ShortcutOptions = {
|
||||
enabled: true,
|
||||
}
|
||||
) {
|
||||
const { globalHotkeysEnabled } = useGlobalHotkeys();
|
||||
return useHotkeys(KEYS[key], cb, {
|
||||
enabled: !options.ignoreGlobalHotkeysStatus ? globalHotkeysEnabled : true,
|
||||
enableOnFormTags: ['INPUT'],
|
||||
});
|
||||
return useHotkeys(
|
||||
KEYS[key],
|
||||
(event) => {
|
||||
event.preventDefault();
|
||||
cb();
|
||||
},
|
||||
{
|
||||
enabled: key === 'ESCAPE_KEY' ? true : enabled && globalHotkeysEnabled,
|
||||
enableOnFormTags: ['INPUT'],
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user