Passed
Pull Request — dev (#45)
by James
03:39
created

App.js ➔ App   B

Complexity

Conditions 3

Size

Total Lines 39
Code Lines 37

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 37
dl 0
loc 39
rs 8.9919
c 0
b 0
f 0
1
import React, { useEffect } from "react";
2
import { BrowserRouter, Route, Routes } from "react-router-dom";
3
import {
4
  Dashboard,
5
  MapOverview,
6
  Cities,
7
  Customers,
8
  Scooters,
9
  Login,
10
  Settings,
11
  ScooterSelect,
12
  CitySelect,
13
  Zones,
14
  Prepaid,
15
} from "./pages";
16
import { Sidebar } from "./components";
17
import { useStateContext } from "./contexts/ContextProvider";
18
import { auth } from "./models/auth";
19
20
function App() {
21
  const { isLoggedIn, setIsLoggedIn } = useStateContext();
22
23
  useEffect(() => {
24
    function checkloggedIn() {
25
      setIsLoggedIn(auth.loggedIn());
26
    }
27
    checkloggedIn();
28
    setInterval(checkloggedIn(), 1000 * 60);
29
  }, []);
30
31
  if (!isLoggedIn) {
32
    return <Login />;
33
  }
34
35
  return (
36
    <>
37
      <div className="flex relative">
38
        <Sidebar />
39
40
        <Routes>
41
          {/* Dashboard */}
42
          <Route path="/" element={<Dashboard />} />
43
          <Route path="/dashboard" element={<Dashboard />} />
44
          {/* The rest */}
45
          <Route path="/map" element={<MapOverview />} />
46
          <Route path="/cities" element={<Cities />} />
47
          <Route path="/scooters" element={<Scooters />} />
48
          <Route path="/customers" element={<Customers />} />
49
          <Route path="/settings" element={<Settings />} />
50
          <Route path="/prepaid" element={<Prepaid />} />
51
52
          <Route path="/scooters/select" element={<ScooterSelect />} />
53
          <Route path="/cities/select" element={<CitySelect />} />
54
          <Route path="/cities/select/zones" element={<Zones />} />
55
        </Routes>
56
      </div>
57
    </>
58
  );
59
}
60
61
export default App;
62