fix(admin): collapse inactive sidebar sections by default and fix toggle logic
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
# Claude Code Rules
|
||||
|
||||
Always read [docs/DEV.md](docs/DEV.md) at the start of every conversation before doing any work in this project.
|
||||
Always read and respect [docs/DEV.md](docs/DEV.md) at the start of every conversation before doing any work in this project.
|
||||
|
||||
@@ -23,17 +23,26 @@ function resolveIcon(iconNameOrComponent) {
|
||||
const AdminSidebar = ({ isMobileMenuOpen, setIsMobileMenuOpen, appName, enabledModules, navigationSections: serverNavigationSections }) => {
|
||||
const pathname = usePathname();
|
||||
|
||||
const [collapsedSections, setCollapsedSections] = useState(new Set());
|
||||
const [collapsedSections, setCollapsedSections] = useState(() => {
|
||||
const initial = new Set();
|
||||
serverNavigationSections.forEach(section => {
|
||||
const isActive = section.items.some(item =>
|
||||
pathname === item.href || pathname.startsWith(item.href + '/')
|
||||
);
|
||||
if (!isActive) initial.add(section.id);
|
||||
});
|
||||
return initial;
|
||||
});
|
||||
|
||||
const toggleSection = (sectionId) => {
|
||||
setCollapsedSections(prev => {
|
||||
const newCollapsed = new Set(prev);
|
||||
if (newCollapsed.has(sectionId)) {
|
||||
newCollapsed.delete(sectionId);
|
||||
const next = new Set(prev);
|
||||
if (next.has(sectionId)) {
|
||||
next.delete(sectionId);
|
||||
} else {
|
||||
newCollapsed.add(sectionId);
|
||||
next.add(sectionId);
|
||||
}
|
||||
return newCollapsed;
|
||||
return next;
|
||||
});
|
||||
};
|
||||
|
||||
@@ -105,7 +114,7 @@ const AdminSidebar = ({ isMobileMenuOpen, setIsMobileMenuOpen, appName, enabledM
|
||||
);
|
||||
}
|
||||
|
||||
const isCollapsed = !collapsedSections.has(section.id) && !isSectionActive(section);
|
||||
const isCollapsed = collapsedSections.has(section.id) && !isSectionActive(section);
|
||||
const isActive = isSectionActive(section);
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user