Feat/better hotkeys scope (#526)

* Working version

* fix

* Fixed console log

* Fix lint

* wip

* Fix

* Fix

* consolelog

---------

Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
Lucas Bordeau
2023-07-08 03:53:05 +02:00
committed by GitHub
parent 611cda1f41
commit 66dcc9b2e1
77 changed files with 1240 additions and 454 deletions

View File

@ -1,8 +1,8 @@
import { useEffect } from 'react';
import styled from '@emotion/styled';
import { useRecoilState } from 'recoil';
import { captureHotkeyTypeInFocusState } from '@/hotkeys/states/captureHotkeyTypeInFocusState';
import { useHotkeysScopeOnBooleanState } from '@/hotkeys/hooks/useHotkeysScopeOnBooleanState';
import { InternalHotkeysScope } from '@/hotkeys/types/internal/InternalHotkeysScope';
import { isDefined } from '@/utils/type-guards/isDefined';
import { Panel } from '../../Panel';
@ -18,14 +18,14 @@ const StyledRightDrawer = styled.div`
`;
export function RightDrawer() {
const [, setCaptureHotkeyTypeInFocus] = useRecoilState(
captureHotkeyTypeInFocusState,
);
const [isRightDrawerOpen] = useRecoilState(isRightDrawerOpenState);
const [rightDrawerPage] = useRecoilState(rightDrawerPageState);
useEffect(() => {
setCaptureHotkeyTypeInFocus(isRightDrawerOpen);
}, [isRightDrawerOpen, setCaptureHotkeyTypeInFocus]);
useHotkeysScopeOnBooleanState(
{ scope: InternalHotkeysScope.RightDrawer },
isRightDrawerOpen,
);
if (!isRightDrawerOpen || !isDefined(rightDrawerPage)) {
return <></>;
}

View File

@ -1,7 +1,8 @@
import { ReactNode } from 'react';
import styled from '@emotion/styled';
import { useDirectHotkeys } from '@/hotkeys/hooks/useDirectHotkeys';
import { useScopedHotkeys } from '@/hotkeys/hooks/useScopedHotkeys';
import { InternalHotkeysScope } from '@/hotkeys/types/internal/InternalHotkeysScope';
import { IconPlus } from '@/ui/icons/index';
import NavCollapseButton from '../navbar/NavCollapseButton';
@ -50,7 +51,7 @@ type OwnProps = {
};
export function TopBar({ title, icon, onAddButtonClick }: OwnProps) {
useDirectHotkeys('c', () => onAddButtonClick && onAddButtonClick());
useScopedHotkeys('c', () => onAddButtonClick?.(), InternalHotkeysScope.Table);
return (
<>