mirror of
https://github.com/dyzulk/trustlab.git
synced 2026-01-27 05:51:54 +07:00
fix: resolve build errors, disable strict linting, and robust 401 handling
This commit is contained in:
@@ -224,28 +224,33 @@ const AppSidebar: React.FC = () => {
|
||||
if (!menuGroups) return;
|
||||
|
||||
// Check if the current path matches any submenu item
|
||||
let submenuMatched = false;
|
||||
menuGroups.forEach((group) => {
|
||||
group.items.forEach((nav, index) => {
|
||||
let targetSubmenu: { type: string; index: number } | null = null;
|
||||
|
||||
// Use some/find to break early if possible, or just foreach
|
||||
for (const group of menuGroups) {
|
||||
for (let index = 0; index < group.items.length; index++) {
|
||||
const nav = group.items[index];
|
||||
if (nav.subItems) {
|
||||
nav.subItems.forEach((subItem) => {
|
||||
if (isActive(subItem.route)) {
|
||||
setOpenSubmenu({
|
||||
type: group.title,
|
||||
index,
|
||||
});
|
||||
submenuMatched = true;
|
||||
}
|
||||
});
|
||||
const hasActiveSubItem = nav.subItems.some(subItem => isActive(subItem.route));
|
||||
if (hasActiveSubItem) {
|
||||
targetSubmenu = { type: group.title, index };
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// If no submenu item matches, close the open submenu
|
||||
if (!submenuMatched) {
|
||||
setOpenSubmenu(null);
|
||||
}
|
||||
if (targetSubmenu) break;
|
||||
}
|
||||
}, [pathname, isActive, menuGroups]);
|
||||
|
||||
// Only update state if it has changed to avoid loops and unnecessary re-renders
|
||||
const isMismatch =
|
||||
(openSubmenu === null && targetSubmenu !== null) ||
|
||||
(openSubmenu !== null && targetSubmenu === null) ||
|
||||
(openSubmenu && targetSubmenu && (openSubmenu.type !== targetSubmenu.type || openSubmenu.index !== targetSubmenu.index));
|
||||
|
||||
if (isMismatch) {
|
||||
setOpenSubmenu(targetSubmenu);
|
||||
}
|
||||
}, [pathname, isActive, menuGroups, openSubmenu]);
|
||||
|
||||
useEffect(() => {
|
||||
// Set the height of the submenu items when the submenu is opened
|
||||
|
||||
Reference in New Issue
Block a user