Migrate dropdown to scope map (#3338)
* Migrate dropdown to scope map * Run lintr * Move Dropdown Scope internally * Fix * Fix lint --------- Co-authored-by: Thomas Trompette <thomast@twenty.com> Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
@ -1,36 +1,29 @@
|
||||
import { useRecoilState } from 'recoil';
|
||||
|
||||
import { useDropdownScopedStates } from '@/ui/layout/dropdown/hooks/internal/useDropdownScopedStates';
|
||||
import { getDropdownScopeInjectors } from '@/ui/layout/dropdown/utils/internal/getDropdownScopeInjectors';
|
||||
import { useDropdownStates } from '@/ui/layout/dropdown/hooks/internal/useDropdownStates';
|
||||
import { usePreviousHotkeyScope } from '@/ui/utilities/hotkey/hooks/usePreviousHotkeyScope';
|
||||
|
||||
export const useDropdown = (dropdownId?: string) => {
|
||||
const { injectStateWithDropdownScopeId, scopeId } = useDropdownScopedStates({
|
||||
dropdownScopeId: dropdownId,
|
||||
});
|
||||
|
||||
const {
|
||||
dropdownHotkeyScopeScopeInjector,
|
||||
dropdownWidthScopeInjector,
|
||||
isDropdownOpenScopeInjector,
|
||||
} = getDropdownScopeInjectors();
|
||||
scopeId,
|
||||
dropdownHotkeyScopeState,
|
||||
dropdownWidthState,
|
||||
isDropdownOpenState,
|
||||
} = useDropdownStates({
|
||||
dropdownScopeId: `${dropdownId}-scope`,
|
||||
});
|
||||
|
||||
const {
|
||||
setHotkeyScopeAndMemorizePreviousScope,
|
||||
goBackToPreviousHotkeyScope,
|
||||
} = usePreviousHotkeyScope();
|
||||
|
||||
const [dropdownHotkeyScope, setDropdownHotkeyScope] = useRecoilState(
|
||||
injectStateWithDropdownScopeId(dropdownHotkeyScopeScopeInjector),
|
||||
);
|
||||
const [dropdownHotkeyScope] = useRecoilState(dropdownHotkeyScopeState);
|
||||
|
||||
const [dropdownWidth, setDropdownWidth] = useRecoilState(
|
||||
injectStateWithDropdownScopeId(dropdownWidthScopeInjector),
|
||||
);
|
||||
const [dropdownWidth, setDropdownWidth] = useRecoilState(dropdownWidthState);
|
||||
|
||||
const [isDropdownOpen, setIsDropdownOpen] = useRecoilState(
|
||||
injectStateWithDropdownScopeId(isDropdownOpenScopeInjector),
|
||||
);
|
||||
const [isDropdownOpen, setIsDropdownOpen] =
|
||||
useRecoilState(isDropdownOpenState);
|
||||
|
||||
const closeDropdown = () => {
|
||||
goBackToPreviousHotkeyScope();
|
||||
@ -61,8 +54,6 @@ export const useDropdown = (dropdownId?: string) => {
|
||||
closeDropdown,
|
||||
toggleDropdown,
|
||||
openDropdown,
|
||||
dropdownHotkeyScope,
|
||||
setDropdownHotkeyScope,
|
||||
dropdownWidth,
|
||||
setDropdownWidth,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user