source: reactapp/src/App.js@ 4abf55a

main
Last change on this file since 4abf55a was af801e3, checked in by viktor <viktor@…>, 19 months ago

finished edit/delete/displace opinion/thread from report (react); todo reporting user/opinion/thread interface, public user pages and messaging (springboot)

  • Property mode set to 100644
File size: 2.5 KB
Line 
1import Professor from "./Pages/Professor";
2import SearchResults from "./Pages/SearchResults";
3import Login from "./Pages/Login";
4import Registration from "./Pages/Registration";
5import { BrowserRouter, Routes, Route, Navigate } from "react-router-dom";
6import Home from "./Pages/Home";
7import UserDashboard from "./Pages/UserDashboard";
8import Subject from "./Pages/Subject";
9import University from "./Pages/University";
10import Faculty from "./Pages/Faculty";
11import { useEffect, useState, useMemo } from "react";
12import AuthApi from "./api/AuthApi";
13import Cookies from "js-cookie";
14import NotFound from "./Pages/NotFound";
15import Topic from "./Pages/Topic";
16import LoadingSpinner from "./Components/Styled/LoadingSpinner.style";
17
18export default function App() {
19 const [auth, setAuth] = useState(false);
20 const variableAuth = useMemo(() => ({ auth, setAuth }), [auth]);
21 const [authLoaded, setAuthLoaded] = useState(false);
22
23 const readCookie = async () => {
24 const session = Cookies.get("JSESSIONID");
25 if (session) {
26 setAuth(true);
27 } else {
28 setAuth(false);
29 }
30 setAuthLoaded(true);
31 };
32
33 useEffect(() => {
34 document.title = "profesori.mk";
35 readCookie();
36 }, []);
37
38 const ProtectedRoute = ({ auth, children }) => {
39 if (authLoaded) {
40 if (!auth) {
41 return <Navigate to="/login" replace />;
42 }
43 return children;
44 } else {
45 return <LoadingSpinner/>;
46 }
47 };
48
49 return (
50 <AuthApi.Provider value={variableAuth}>
51 <BrowserRouter>
52 <Routes>
53 <Route path="/" element={<Home />}>
54 <Route path="login" element={<Login />}></Route>
55 <Route path="registration" element={<Registration />}></Route>
56 <Route path="professor">
57 <Route path=":professorId" element={<Professor />} />
58 </Route>
59 <Route path="university/:universityId" element={<University />} />
60 <Route path="faculty/:facultyId" element={<Faculty />} />
61 <Route path="subject/:subjectId" element={<Subject />} />
62 <Route path="topic/:topicId" element={<Topic />} />
63 <Route path="search" element={<SearchResults />}></Route>
64 <Route
65 path="user_dashboard"
66 element={
67 <ProtectedRoute auth={auth}>{<UserDashboard />}</ProtectedRoute>
68 }
69 ></Route>
70 </Route>
71 <Route path="*" element={<NotFound />} />
72 </Routes>
73 </BrowserRouter>
74 </AuthApi.Provider>
75 );
76}
Note: See TracBrowser for help on using the repository browser.