Files
twenty_crm/front/src/modules/hotkeys/hooks/internal/usePreviousHotkeysScope.ts
Lucas Bordeau 5f98b70c6a Fix/scope hotkeys (#581)
* WIP

* asd

* Fix

* Fix lint

* Removed console log

* asd

* Removed isDefined

* Fix/debounce company card onchange (#580)

* Add internal state and debounce for editable text card

* Use debounce for date fields too

* Update refetch

* Nit

* Removed comments

* Ménage

---------

Co-authored-by: Emilien Chauvet <emilien.chauvet.enpc@gmail.com>
2023-07-11 01:53:46 +00:00

40 lines
1.1 KiB
TypeScript

import { useState } from 'react';
import { useRecoilValue } from 'recoil';
import { currentHotkeysScopeState } from '@/hotkeys/states/internal/currentHotkeysScopeState';
import { CustomHotkeysScopes } from '@/hotkeys/types/internal/CustomHotkeysScope';
import { HotkeysScope } from '@/hotkeys/types/internal/HotkeysScope';
import { useSetHotkeysScope } from '../useSetHotkeysScope';
export function usePreviousHotkeysScope() {
const [previousHotkeysScope, setPreviousHotkeysScope] =
useState<HotkeysScope | null>();
const setHotkeysScope = useSetHotkeysScope();
const currentHotkeysScope = useRecoilValue(currentHotkeysScopeState);
function goBackToPreviousHotkeysScope() {
if (previousHotkeysScope) {
setHotkeysScope(
previousHotkeysScope.scope,
previousHotkeysScope.customScopes,
);
}
}
function setHotkeysScopeAndMemorizePreviousScope(
scope: string,
customScopes?: CustomHotkeysScopes,
) {
setPreviousHotkeysScope(currentHotkeysScope);
setHotkeysScope(scope, customScopes);
}
return {
setHotkeysScopeAndMemorizePreviousScope,
goBackToPreviousHotkeysScope,
};
}