* 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>
40 lines
1.1 KiB
TypeScript
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,
|
|
};
|
|
}
|