Ignore:
Timestamp:
12/12/24 17:06:06 (5 weeks ago)
Author:
stefan toskovski <stefantoska84@…>
Branches:
main
Parents:
d565449
Message:

Pred finalna verzija

File:
1 edited

Legend:

Unmodified
Added
Removed
  • imaps-frontend/src/App.jsx

    rd565449 r0c6b92a  
    11// eslint-disable-next-line no-unused-vars
    2 import React, { useState, useEffect } from "react";
    3 import { BrowserRouter as Router, Routes, Route } from "react-router-dom";
    4 import FinkiMaps from "./pages/FinkiMaps/FinkiMaps";
    5 import Maps from "./pages/Maps/Maps";
     2import React from "react";
     3import {BrowserRouter as Router, Route, Routes} from "react-router-dom";
     4import BrowseMaps from "./pages/BrowseMaps/BrowseMaps.jsx";
    65import LoginPage from "./pages/Login/Login";
    76import Signup from "./pages/Signup/Signup";
     
    1110import ProtectedRoute from "./components/ProtectedRoute/ProtectedRoute";
    1211import "./App.css";
    13 import HttpService from "./scripts/net/HttpService";
     12import MapView from "./pages/MapView/MapView.jsx";
     13import MyMaps from "./pages/MyMaps/MyMaps.jsx";
     14
     15import '@fontsource/roboto/300.css';
     16import '@fontsource/roboto/400.css';
     17import '@fontsource/roboto/500.css';
     18import '@fontsource/roboto/700.css';
     19import {AppProvider} from "./components/AppContext/AppContext.jsx";
     20import AdminPage from "./pages/AdminPage/AdminPage.jsx";
     21
    1422
    1523function App() {
    16   const [isAuthenticated, setIsAuthenticated] = useState(false);
    17   const [loading, setLoading] = useState(true);
    1824
    19   useEffect(() => {
    20     const token = localStorage.getItem("token");
    21     const httpService = new HttpService("http://localhost:8080/api/auth");
     25    return (
    2226
    23     const verifyToken = async () => {
    24       try {
    25         const response = await httpService.get(`/verify?token=${token}`);
    26         if (response.username) {
    27           setIsAuthenticated(true);
    28           console.log("good");
    29         }
    30       } catch (error) {
    31         console.log("ERROR: ", error);
    32         setIsAuthenticated(false);
    33       } finally {
    34         setLoading(false);
    35       }
    36     };
     27        <AppProvider>
     28            <Router>
     29                <Routes>
    3730
    38     if (token) {
    39       verifyToken();
    40       //setLoading(false);
    41     } else {
    42       setIsAuthenticated(false);
    43       setLoading(false);
    44     }
    45   }, []);
     31                    <Route element={<ProtectedRoute/>}>
     32                        <Route path="/myMaps/:mapName/Draw" element={<Draw/>}/>
     33                        <Route path="/myMaps" element={<MyMaps/>}/>
     34                        <Route path="/myMaps/:mapName/View" element={<MapView isPrivate={true}/>}/>
     35                        <Route path="/Admin" element={<AdminPage/>}/>
     36                    </Route>
     37                    <Route path="/" element={<IMaps/>}/>
     38                    <Route path="/Maps/:mapName/View" element={<MapView isPrivate={false}/>}/>
     39                    <Route path="/Maps" element={<BrowseMaps/>}/>
    4640
    47   const handleLogin = (token) => {
    48     localStorage.setItem("token", token);
    49     setIsAuthenticated(true);
    50   };
    5141
    52   if (loading) {
    53     return (
    54       <div className="loading-container">
    55         <div className="spinner"></div>
    56         <p>Loading, please wait...</p>
    57       </div>
     42                    <Route path="/Login" element={<LoginPage/>}/>
     43                    <Route path="/Signup" element={<Signup/>}/>
     44
     45                    <Route path="*" element={<Error/>}/>
     46                </Routes>
     47            </Router>
     48        </AppProvider>
     49
     50
    5851    );
    59   }
    60 
    61   return (
    62     <Router>
    63       <Routes>
    64         <Route path="/" element={<IMaps />} />
    65         <Route path="/Maps/FinkiMaps/View" element={<FinkiMaps />} />
    66         <Route path="/Maps" element={<Maps />} />
    67         <Route path="/Login" element={<LoginPage onLogin={handleLogin} />} />
    68         <Route path="/Signup" element={<Signup />} />
    69 
    70         <Route element={<ProtectedRoute isAuthenticated={isAuthenticated} />}>
    71           <Route path="/Maps/FinkiMaps/Draw" element={<Draw />} />
    72         </Route>
    73 
    74         <Route path="*" element={<Error />} />
    75       </Routes>
    76     </Router>
    77   );
    7852}
    7953
Note: See TracChangeset for help on using the changeset viewer.