github.com/quickfeed/quickfeed@v0.0.0-20240507093252-ed8ca812a09c/public/src/App.tsx (about) 1 import React from 'react' 2 import { useAppState } from './overmind' 3 import NavBar from "./components/NavBar" 4 import { Switch, Route } from 'react-router-dom' 5 import Profile from "./components/profile/Profile" 6 import CoursePage from "./pages/CoursePage" 7 import Courses from "./components/Courses" 8 import AdminPage from './pages/AdminPage' 9 import Loading from './components/Loading' 10 import Dashboard from './components/Dashboard' 11 import AboutPage from './pages/AboutPage' 12 13 const App = (): JSX.Element => { 14 const state = useAppState() 15 16 const Main = () => { 17 // Determine which routes are available to the user depending on the state 18 if (state.isLoading) { 19 return <Loading /> 20 } else if (!state.isValid && state.isLoggedIn) { 21 // user logged in without profile information: redirect to Profile page 22 return ( 23 <Switch> 24 <Route path="/" component={Profile} /> 25 <Route path="/profile" component={Profile} /> 26 </Switch> 27 ) 28 } else if (state.isLoggedIn) { 29 // user logged in: show Dashboard page 30 return ( 31 <Switch> 32 <Route path="/" exact component={Dashboard} /> 33 <Route path="/about" component={AboutPage} /> 34 <Route path="/profile" component={Profile} /> 35 <Route path="/course/:id" component={CoursePage} /> 36 <Route path="/courses" exact component={Courses} /> 37 <Route path="/admin" component={AdminPage} /> 38 </Switch> 39 ) 40 } else { 41 // user not logged in: show About page 42 return ( 43 <Switch> 44 <Route path="/" component={AboutPage} /> 45 </Switch> 46 ) 47 } 48 } 49 50 return ( 51 <div> 52 <NavBar /> 53 <div className="app wrapper"> 54 <div id={state.showFavorites ? "content" : "content-full"}> 55 {Main()} 56 </div> 57 </div> 58 </div> 59 ) 60 } 61 62 export default App