mirror of
https://github.com/twentyhq/twenty
synced 2026-04-21 13:37:22 +00:00
Enhance navigation menu item folder state management
- Introduced a new state variable `isManuallyClosed` to track manual closure of navigation menu items. - Updated the logic for determining if a folder is open to account for manual closure, ensuring a more accurate representation of the folder's state. - Adjusted the toggle handler to set `isManuallyClosed` based on the current open state, improving user experience in navigation interactions.
This commit is contained in:
parent
65e01400c0
commit
74b8049817
1 changed files with 9 additions and 3 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import { isNonEmptyString } from '@sniptt/guards';
|
||||
import { useState } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { NavigationMenuItemType } from 'twenty-shared/types';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
|
|
@ -42,11 +43,13 @@ export const useNavigationMenuItemFolderOpenState = ({
|
|||
lastClickedNavigationMenuItemIdState,
|
||||
);
|
||||
|
||||
const [isManuallyClosed, setIsManuallyClosed] = useState(false);
|
||||
|
||||
const isExplicitlyOpen = openNavigationMenuItemFolderIds.includes(folderId);
|
||||
const hasActiveChild = folderChildrenNavigationMenuItems.some((item) =>
|
||||
activeNavigationMenuItemIds.includes(item.id),
|
||||
);
|
||||
const isOpen = isExplicitlyOpen || hasActiveChild;
|
||||
const isOpen = isExplicitlyOpen || (hasActiveChild && !isManuallyClosed);
|
||||
|
||||
const handleToggle = () => {
|
||||
if (isMobile) {
|
||||
|
|
@ -55,10 +58,13 @@ export const useNavigationMenuItemFolderOpenState = ({
|
|||
);
|
||||
} else {
|
||||
setOpenNavigationMenuItemFolderIds((current) =>
|
||||
current.includes(folderId)
|
||||
isOpen
|
||||
? current.filter((id) => id !== folderId)
|
||||
: [...current, folderId],
|
||||
: current.includes(folderId)
|
||||
? current
|
||||
: [...current, folderId],
|
||||
);
|
||||
setIsManuallyClosed(isOpen);
|
||||
}
|
||||
|
||||
if (!isOpen) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue