navigation
This commit is contained in:
@@ -18,13 +18,13 @@ import TableViewIcon from '@mui/icons-material/TableView';
|
||||
import DashboardIcon from '@mui/icons-material/Dashboard';
|
||||
import LogoutIcon from '@mui/icons-material/Logout';
|
||||
import { ResourceConfig } from '../types/config';
|
||||
import { useLocation, useNavigate } from 'react-router-dom';
|
||||
|
||||
const drawerWidth = 240;
|
||||
|
||||
interface AdminLayoutProps {
|
||||
children: React.ReactNode;
|
||||
onSelectResource: (resourceName: string | null) => void;
|
||||
selectedResourceName: string | null;
|
||||
onLogout: () => void;
|
||||
username?: string;
|
||||
resources: ResourceConfig[];
|
||||
@@ -33,11 +33,14 @@ interface AdminLayoutProps {
|
||||
export default function AdminLayout({
|
||||
children,
|
||||
onSelectResource,
|
||||
selectedResourceName,
|
||||
onLogout,
|
||||
username,
|
||||
resources,
|
||||
}: AdminLayoutProps) {
|
||||
const location = useLocation();
|
||||
const navigate = useNavigate();
|
||||
const activeResourceName = location.pathname.split('/')[1] || null;
|
||||
|
||||
return (
|
||||
<Box sx={{ display: 'flex' }}>
|
||||
<CssBaseline />
|
||||
@@ -67,8 +70,8 @@ export default function AdminLayout({
|
||||
<List>
|
||||
<ListItem disablePadding>
|
||||
<ListItemButton
|
||||
selected={selectedResourceName === null}
|
||||
onClick={() => onSelectResource(null)}
|
||||
selected={location.pathname === '/'}
|
||||
onClick={() => navigate('/')}
|
||||
>
|
||||
<ListItemIcon>
|
||||
<DashboardIcon />
|
||||
@@ -82,7 +85,7 @@ export default function AdminLayout({
|
||||
{resources.map((res) => (
|
||||
<ListItem key={res.name} disablePadding>
|
||||
<ListItemButton
|
||||
selected={selectedResourceName === res.name}
|
||||
selected={activeResourceName === res.name}
|
||||
onClick={() => onSelectResource(res.name)}
|
||||
>
|
||||
<ListItemIcon>
|
||||
|
||||
Reference in New Issue
Block a user