diff options
Diffstat (limited to 'src/app')
-rw-r--r-- | src/app/AuthenticatedApp.js | 41 | ||||
-rw-r--r-- | src/app/ProfessorRoutes.js | 22 | ||||
-rw-r--r-- | src/app/StudentRoutes.js | 31 | ||||
-rw-r--r-- | src/app/data.js | 1 |
4 files changed, 72 insertions, 23 deletions
diff --git a/src/app/AuthenticatedApp.js b/src/app/AuthenticatedApp.js index 80d66be..b4a9412 100644 --- a/src/app/AuthenticatedApp.js +++ b/src/app/AuthenticatedApp.js @@ -1,22 +1,20 @@ -import { Navigate, Route, Routes, useNavigate } from 'react-router-dom'; +import { lazy } from 'react'; +import { useNavigate } from 'react-router-dom'; import { Container } from '@mui/system'; -import { useUser } from '../context/user'; import { useAuthState } from '../context/auth'; +import { useUser } from '../context/user'; import MainMenu from '../components/MainMenu'; -import Home from '../screens/Home'; -import Information from '../screens/Information'; -import Calendar from '../screens/Calendar'; import useLayoutType from '../hooks/useLayoutType'; import Toolbar from '../components/Toolbar'; -import Classroom from '../screens/Classroom'; -import Assignment from '../screens/Assignment'; -import Profile from '../screens/Profile'; import { avatarMenuOptions, menuOptions } from './data'; import styles from './styles'; +const StudentRoutes = lazy(() => import('./StudentRoutes')); +const ProfessorRoutes = lazy(() => import('./ProfessorRoutes')); + function AuthenticatedApp() { const navigate = useNavigate(); const { state } = useUser(); @@ -24,6 +22,17 @@ function AuthenticatedApp() { const layoutType = useLayoutType(); const { container, toolbar } = styles[layoutType]; + const routeResolver = role => { + switch (role) { + case 'STUDENT': + return <StudentRoutes />; + case 'PROFESSOR': + return <ProfessorRoutes />; + default: + return null; + } + }; + return ( state && state.user && ( @@ -43,21 +52,7 @@ function AuthenticatedApp() { options={menuOptions(state.pathname)} layoutType={layoutType} /> - <Routes> - <Route path="/home" element={<Home />} /> - <Route path="/info" element={<Information />} /> - <Route path="/calendar" element={<Calendar />} /> - <Route path="/profile" element={<Profile />} /> - <Route path="/class"> - <Route path=":id" element={<Classroom />} /> - </Route> - <Route path="/assignment"> - <Route path=":id" element={<Assignment />} /> - </Route> - <Route path="/login" element={<Navigate to="/home" />} /> - <Route path="/register" element={<Navigate to="/home" />} /> - <Route path="/" element={<Navigate to="/home" />} /> - </Routes> + {routeResolver(state.user.role)} </Container> </> ) diff --git a/src/app/ProfessorRoutes.js b/src/app/ProfessorRoutes.js new file mode 100644 index 0000000..ced0d15 --- /dev/null +++ b/src/app/ProfessorRoutes.js @@ -0,0 +1,22 @@ +import { Navigate, Route, Routes } from 'react-router-dom'; +import Classroom from '../screens/professor/Classroom'; +import Home from '../screens/professor/Home'; + +function ProfessorRoutes() { + return ( + <Routes> + <Route path="/calendar" element={<h1>Calendar</h1>} /> + <Route path="/profile" element={<h1>Profile</h1>} /> + <Route path="/class"> + <Route path=":id" element={<Classroom />} /> + </Route> + <Route path="/info" element={<h1>Information</h1>} /> + <Route path="/home" element={<Home />} /> + <Route path="/login" element={<Navigate to="/home" />} /> + <Route path="/register" element={<Navigate to="/home" />} /> + <Route path="/" element={<Navigate to="/home" />} /> + </Routes> + ); +} + +export default ProfessorRoutes; diff --git a/src/app/StudentRoutes.js b/src/app/StudentRoutes.js new file mode 100644 index 0000000..1dc6b4a --- /dev/null +++ b/src/app/StudentRoutes.js @@ -0,0 +1,31 @@ +import { Navigate, Route, Routes } from 'react-router-dom'; + +import Home from '../screens/student/Home'; +import Classroom from '../screens/student/Classroom'; + +import Information from '../screens/Information'; +import Calendar from '../screens/Calendar'; +import Assignment from '../screens/Assignment'; +import Profile from '../screens/Profile'; + +function StudentRoutes() { + return ( + <Routes> + <Route path="/home" element={<Home />} /> + <Route path="/info" element={<Information />} /> + <Route path="/calendar" element={<Calendar />} /> + <Route path="/profile" element={<Profile />} /> + <Route path="/class"> + <Route path=":id" element={<Classroom />} /> + </Route> + <Route path="/assignment"> + <Route path=":id" element={<Assignment />} /> + </Route> + <Route path="/login" element={<Navigate to="/home" />} /> + <Route path="/register" element={<Navigate to="/home" />} /> + <Route path="/" element={<Navigate to="/home" />} /> + </Routes> + ); +} + +export default StudentRoutes; diff --git a/src/app/data.js b/src/app/data.js index e7048f5..647eb01 100644 --- a/src/app/data.js +++ b/src/app/data.js @@ -28,6 +28,7 @@ const menuOptions = activePath => [ isActive: activePath === '/home' || activePath === '/login' || + activePath === '/register' || activePath === '/profile' || activePath === '/' || activePath.indexOf('class') !== -1 || |