fix: resolve build errors, disable strict linting, and robust 401 handling

This commit is contained in:
dyzulk
2026-01-05 23:42:48 +07:00
parent cc921a91e1
commit 8195de344d
6 changed files with 406 additions and 43 deletions

View File

@@ -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