Spaces:
Sleeping
Sleeping
Download frontend-backup/src/components/Layout.tsx from edichat/edi.chat.test: direct link, hf CLI and curl.
- Browser
- Download file 8.2 kB
-
https://huggingface.co/spaces/edichat/edi.chat.test/resolve/main/frontend-backup/src/components/Layout.tsx
- Command line
-
hf download hf://spaces/edichat/edi.chat.test/frontend-backup/src/components/Layout.tsx
-
curl -L -o Layout.tsx https://huggingface.co/spaces/edichat/edi.chat.test/resolve/main/frontend-backup/src/components/Layout.tsx
8.2 kB
| import React, { useState } from 'react'; | |
| import { useLocation, useNavigate } from 'react-router-dom'; | |
| import { | |
| AppBar, | |
| Box, | |
| CssBaseline, | |
| Divider, | |
| Drawer, | |
| IconButton, | |
| List, | |
| ListItem, | |
| ListItemButton, | |
| ListItemIcon, | |
| ListItemText, | |
| Toolbar, | |
| Typography, | |
| Avatar, | |
| Menu, | |
| MenuItem, | |
| } from '@mui/material'; | |
| import { | |
| Menu as MenuIcon, | |
| Dashboard as DashboardIcon, | |
| Chat as ChatIcon, | |
| School as SchoolIcon, | |
| MenuBook as KnowledgeIcon, | |
| Settings as SettingsIcon, | |
| AccountCircle as ProfileIcon, | |
| ExitToApp as LogoutIcon, | |
| Class as FacultyIcon, | |
| Analytics as AnalyticsIcon, | |
| } from '@mui/icons-material'; | |
| import { useAuth } from '../contexts/AuthContext'; | |
| import { NavItem } from '../types'; | |
| const drawerWidth = 240; | |
| interface LayoutProps { | |
| children: React.ReactNode; | |
| } | |
| const Layout: React.FC<LayoutProps> = ({ children }) => { | |
| const { user, logout } = useAuth(); | |
| const location = useLocation(); | |
| const navigate = useNavigate(); | |
| const [mobileOpen, setMobileOpen] = useState(false); | |
| const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null); | |
| const handleDrawerToggle = () => { | |
| setMobileOpen(!mobileOpen); | |
| }; | |
| const handleProfileMenuOpen = (event: React.MouseEvent<HTMLElement>) => { | |
| setAnchorEl(event.currentTarget); | |
| }; | |
| const handleProfileMenuClose = () => { | |
| setAnchorEl(null); | |
| }; | |
| const handleLogout = () => { | |
| handleProfileMenuClose(); | |
| logout(); | |
| }; | |
| // Navigation items based on user role | |
| const getNavItems = (): NavItem[] => { | |
| const baseItems: NavItem[] = [ | |
| { label: 'Dashboard', path: '/dashboard', icon: DashboardIcon }, | |
| { label: 'Chat', path: '/chat', icon: ChatIcon }, | |
| { label: 'Student Services', path: '/student-services', icon: SchoolIcon, roles: ['student'] }, | |
| { label: 'Knowledge Base', path: '/knowledge', icon: KnowledgeIcon }, | |
| ]; | |
| if (user?.role === 'faculty' || user?.role === 'admin') { | |
| baseItems.push( | |
| { label: 'Faculty Dashboard', path: '/faculty/dashboard', icon: FacultyIcon, roles: ['faculty', 'admin'] }, | |
| { label: 'Analytics', path: '/faculty/analytics', icon: AnalyticsIcon, roles: ['faculty', 'admin'] } | |
| ); | |
| } | |
| baseItems.push({ label: 'Settings', path: '/settings', icon: SettingsIcon }); | |
| return baseItems.filter(item => !item.roles || (user && item.roles.includes(user.role))); | |
| }; | |
| const drawer = ( | |
| <Box> | |
| <Toolbar> | |
| <Box sx={{ display: 'flex', alignItems: 'center', gap: 2 }}> | |
| <Box | |
| component="img" | |
| src="/edi.chat.png" | |
| alt="edi.chat logo" | |
| sx={{ | |
| width: 32, | |
| height: 32, | |
| borderRadius: '50%', | |
| objectFit: 'contain', | |
| }} | |
| /> | |
| <Typography variant="h6" noWrap component="div" sx={{ fontSize: '1.1rem' }}> | |
| edi.chat | |
| </Typography> | |
| </Box> | |
| </Toolbar> | |
| <Divider /> | |
| <List> | |
| {getNavItems().map((item) => { | |
| const IconComponent = item.icon!; | |
| const isSelected = location.pathname === item.path || | |
| (item.path !== '/dashboard' && location.pathname.startsWith(item.path)); | |
| return ( | |
| <ListItem key={item.path} disablePadding> | |
| <ListItemButton | |
| selected={isSelected} | |
| onClick={() => navigate(item.path)} | |
| sx={{ | |
| '&.Mui-selected': { | |
| backgroundColor: 'primary.main', | |
| color: 'white', | |
| '&:hover': { | |
| backgroundColor: 'primary.dark', | |
| }, | |
| '& .MuiListItemIcon-root': { | |
| color: 'white', | |
| }, | |
| }, | |
| }} | |
| > | |
| <ListItemIcon> | |
| <IconComponent /> | |
| </ListItemIcon> | |
| <ListItemText primary={item.label} /> | |
| </ListItemButton> | |
| </ListItem> | |
| ); | |
| })} | |
| </List> | |
| </Box> | |
| ); | |
| return ( | |
| <Box sx={{ display: 'flex' }}> | |
| <CssBaseline /> | |
| <AppBar | |
| position="fixed" | |
| sx={{ | |
| width: { sm: `calc(100% - ${drawerWidth}px)` }, | |
| ml: { sm: `${drawerWidth}px` }, | |
| }} | |
| > | |
| <Toolbar> | |
| <IconButton | |
| color="inherit" | |
| aria-label="open drawer" | |
| edge="start" | |
| onClick={handleDrawerToggle} | |
| sx={{ mr: 2, display: { sm: 'none' } }} | |
| > | |
| <MenuIcon /> | |
| </IconButton> | |
| <Typography variant="h6" noWrap component="div" sx={{ flexGrow: 1 }}> | |
| {(() => { | |
| const path = location.pathname; | |
| if (path === '/dashboard') return 'Dashboard'; | |
| if (path === '/chat' || path.startsWith('/chat/')) return 'Chat'; | |
| if (path === '/student-services') return 'Student Services'; | |
| if (path === '/knowledge') return 'Knowledge Base'; | |
| if (path === '/settings') return 'Settings'; | |
| if (path === '/profile') return 'Profile'; | |
| if (path.startsWith('/faculty')) return 'Faculty Portal'; | |
| return 'edi.chat'; | |
| })()} | |
| </Typography> | |
| <IconButton | |
| size="large" | |
| aria-label="account of current user" | |
| aria-controls="profile-menu" | |
| aria-haspopup="true" | |
| onClick={handleProfileMenuOpen} | |
| color="inherit" | |
| > | |
| <Avatar | |
| sx={{ | |
| width: 32, | |
| height: 32, | |
| bgcolor: 'transparent', | |
| }} | |
| src="/uga-logo.png" | |
| alt="UGA Logo" | |
| > | |
| {user?.firstName?.[0]}{user?.lastName?.[0]} | |
| </Avatar> | |
| </IconButton> | |
| </Toolbar> | |
| </AppBar> | |
| <Menu | |
| id="profile-menu" | |
| anchorEl={anchorEl} | |
| anchorOrigin={{ | |
| vertical: 'top', | |
| horizontal: 'right', | |
| }} | |
| keepMounted | |
| transformOrigin={{ | |
| vertical: 'top', | |
| horizontal: 'right', | |
| }} | |
| open={Boolean(anchorEl)} | |
| onClose={handleProfileMenuClose} | |
| > | |
| <MenuItem onClick={() => { handleProfileMenuClose(); navigate('/profile'); }}> | |
| <ListItemIcon> | |
| <ProfileIcon fontSize="small" /> | |
| </ListItemIcon> | |
| <ListItemText> | |
| <Typography variant="body2"> | |
| {user?.firstName} {user?.lastName} | |
| </Typography> | |
| <Typography variant="caption" color="textSecondary"> | |
| {user?.email} | |
| </Typography> | |
| </ListItemText> | |
| </MenuItem> | |
| <Divider /> | |
| <MenuItem onClick={handleLogout}> | |
| <ListItemIcon> | |
| <LogoutIcon fontSize="small" /> | |
| </ListItemIcon> | |
| Logout | |
| </MenuItem> | |
| </Menu> | |
| <Box | |
| component="nav" | |
| sx={{ width: { sm: drawerWidth }, flexShrink: { sm: 0 } }} | |
| aria-label="navigation" | |
| > | |
| <Drawer | |
| variant="temporary" | |
| open={mobileOpen} | |
| onClose={handleDrawerToggle} | |
| ModalProps={{ | |
| keepMounted: true, // Better open performance on mobile. | |
| }} | |
| sx={{ | |
| display: { xs: 'block', sm: 'none' }, | |
| '& .MuiDrawer-paper': { boxSizing: 'border-box', width: drawerWidth }, | |
| }} | |
| > | |
| {drawer} | |
| </Drawer> | |
| <Drawer | |
| variant="permanent" | |
| sx={{ | |
| display: { xs: 'none', sm: 'block' }, | |
| '& .MuiDrawer-paper': { boxSizing: 'border-box', width: drawerWidth }, | |
| }} | |
| open | |
| > | |
| {drawer} | |
| </Drawer> | |
| </Box> | |
| <Box | |
| component="main" | |
| sx={{ | |
| flexGrow: 1, | |
| p: 3, | |
| width: { sm: `calc(100% - ${drawerWidth}px)` }, | |
| mt: 8, // Account for AppBar height | |
| minHeight: 'calc(100vh - 64px)', | |
| }} | |
| > | |
| {children} | |
| </Box> | |
| </Box> | |
| ); | |
| }; | |
| export default Layout; |