refactor(admin): replace AdminPageTitleContext with direct registry lookup for breadcrumbs
This commit is contained in:
@@ -5,12 +5,10 @@ import { Menu, MenuButton, MenuItem, MenuItems, Transition } from '@headlessui/r
|
||||
import { ChevronDownIcon, User03Icon, DashboardSquare03Icon } from '@zen/core/shared/icons';
|
||||
import { UserAvatar } from '@zen/core/shared/components';
|
||||
import { useRouter, usePathname } from 'next/navigation';
|
||||
import { getPages } from '../registry.js';
|
||||
import { useAdminPageTitle } from './AdminPageTitleContext.js';
|
||||
import { getPage, getPages } from '../registry.js';
|
||||
import { useTheme, getThemeIcon } from '@zen/core/themes';
|
||||
|
||||
const AdminTop = ({ isMobileMenuOpen, setIsMobileMenuOpen, user, onLogout, appName = 'ZEN', navigationSections = [] }) => {
|
||||
const { title: currentPageTitle } = useAdminPageTitle();
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
|
||||
@@ -40,21 +38,17 @@ const AdminTop = ({ isMobileMenuOpen, setIsMobileMenuOpen, user, onLogout, appNa
|
||||
const buildBreadcrumbs = () => {
|
||||
const crumbs = [{ icon: DashboardSquare03Icon, href: '/admin/dashboard' }];
|
||||
const after = pathname.replace(/^\/admin\/?/, '');
|
||||
if (!after) {
|
||||
crumbs.push({ label: currentPageTitle });
|
||||
return crumbs;
|
||||
}
|
||||
|
||||
const segments = after.split('/').filter(Boolean);
|
||||
if (!segments.length || (segments[0] === 'dashboard' && segments.length === 1)) {
|
||||
crumbs.push({ label: currentPageTitle });
|
||||
const [first, second] = segments;
|
||||
const pageTitle = getPage(first || 'dashboard')?.title || '';
|
||||
|
||||
if (!after || !segments.length || (segments[0] === 'dashboard' && segments.length === 1)) {
|
||||
crumbs.push({ label: pageTitle });
|
||||
return crumbs;
|
||||
}
|
||||
|
||||
const [first, second] = segments;
|
||||
|
||||
if (first === 'profile') {
|
||||
crumbs.push({ label: currentPageTitle });
|
||||
crumbs.push({ label: pageTitle });
|
||||
return crumbs;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user