eba997be98
# Replace hotkey scopes by focus stack (Part 6 - Remove Hotkey scopes) This PR is the last part of a refactoring aiming to deprecate the hotkey scopes api in favor of the new focus stack api which is more robust. Part 1: https://github.com/twentyhq/twenty/pull/12673 Part 2: https://github.com/twentyhq/twenty/pull/12798 Part 3: https://github.com/twentyhq/twenty/pull/12910 Part 4: https://github.com/twentyhq/twenty/pull/12933 Part 5: https://github.com/twentyhq/twenty/pull/13106 In this part, we completely remove the hotkey scopes.
73 lines
2.4 KiB
TypeScript
73 lines
2.4 KiB
TypeScript
import { useRecoilCallback } from 'recoil';
|
|
|
|
import { usePushFocusItemToFocusStack } from '@/ui/utilities/focus/hooks/usePushFocusItemToFocusStack';
|
|
import { useRemoveFocusItemFromFocusStackById } from '@/ui/utilities/focus/hooks/useRemoveFocusItemFromFocusStackById';
|
|
import { FocusComponentType } from '@/ui/utilities/focus/types/FocusComponentType';
|
|
import { isKeyboardShortcutMenuOpenedState } from '../states/isKeyboardShortcutMenuOpenedState';
|
|
|
|
export const KEYBOARD_SHORTCUT_MENU_INSTANCE_ID = 'keyboard-shortcut-menu';
|
|
|
|
export const useKeyboardShortcutMenu = () => {
|
|
const { pushFocusItemToFocusStack } = usePushFocusItemToFocusStack();
|
|
const { removeFocusItemFromFocusStackById } =
|
|
useRemoveFocusItemFromFocusStackById();
|
|
|
|
const openKeyboardShortcutMenu = useRecoilCallback(
|
|
({ set }) =>
|
|
() => {
|
|
set(isKeyboardShortcutMenuOpenedState, true);
|
|
pushFocusItemToFocusStack({
|
|
focusId: KEYBOARD_SHORTCUT_MENU_INSTANCE_ID,
|
|
component: {
|
|
type: FocusComponentType.KEYBOARD_SHORTCUT_MENU,
|
|
instanceId: KEYBOARD_SHORTCUT_MENU_INSTANCE_ID,
|
|
},
|
|
globalHotkeysConfig: {
|
|
enableGlobalHotkeysConflictingWithKeyboard: false,
|
|
enableGlobalHotkeysWithModifiers: false,
|
|
},
|
|
});
|
|
},
|
|
[pushFocusItemToFocusStack],
|
|
);
|
|
|
|
const closeKeyboardShortcutMenu = useRecoilCallback(
|
|
({ set, snapshot }) =>
|
|
() => {
|
|
const isKeyboardShortcutMenuOpened = snapshot
|
|
.getLoadable(isKeyboardShortcutMenuOpenedState)
|
|
.getValue();
|
|
|
|
if (isKeyboardShortcutMenuOpened) {
|
|
set(isKeyboardShortcutMenuOpenedState, false);
|
|
removeFocusItemFromFocusStackById({
|
|
focusId: KEYBOARD_SHORTCUT_MENU_INSTANCE_ID,
|
|
});
|
|
}
|
|
},
|
|
[removeFocusItemFromFocusStackById],
|
|
);
|
|
|
|
const toggleKeyboardShortcutMenu = useRecoilCallback(
|
|
({ snapshot }) =>
|
|
() => {
|
|
const isKeyboardShortcutMenuOpened = snapshot
|
|
.getLoadable(isKeyboardShortcutMenuOpenedState)
|
|
.getValue();
|
|
|
|
if (isKeyboardShortcutMenuOpened === false) {
|
|
openKeyboardShortcutMenu();
|
|
} else {
|
|
closeKeyboardShortcutMenu();
|
|
}
|
|
},
|
|
[closeKeyboardShortcutMenu, openKeyboardShortcutMenu],
|
|
);
|
|
|
|
return {
|
|
toggleKeyboardShortcutMenu,
|
|
openKeyboardShortcutMenu,
|
|
closeKeyboardShortcutMenu,
|
|
};
|
|
};
|