Passed
Pull Request — dev (#9)
by Kasper
02:13
created

App.jsx ➔ checkloggedIn   A

Complexity

Conditions 3

Size

Total Lines 8
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 3
1
import React, { useState, useEffect } from "react";
2
import { Route, Routes } from "react-router-dom";
3
import { Footer, Header, LoginForm } from "./components";
4
import auth from "./models/auth.js"
5
import { Home, LoginFailure, LoginSuccess, Logout, Account } from "./pages";
6
import { useStateContext } from "./contexts/ContextProvider";
7
const App = () => {
8
  const [displayForm, setDisplayForm] = useState(false);
9
  const { setIsLoggedIn } = useStateContext();
10
  useEffect(() => {
11
    async function checkloggedIn() {
12
      const res = await auth.loggedIn()
13
      const resGoogle = await auth.getUser()
14
      console.log(resGoogle);
15
      if(res) {
16
        setIsLoggedIn(true);
17
      } else if(resGoogle) {
18
        setIsLoggedIn(true);
19
      }
20
    }
21
    checkloggedIn();
22
  });
23
24
  const overlay = () => {
25
    let state = { click: "auto", backdrop: "blur(0px)" };
26
    document.body.style.overflow = "visible";
27
    if (displayForm) {
28
      document.body.style.overflow = "hidden";
29
      state = { click: "none", backdrop: "blur(4px)" };
30
    }
31
    return state;
32
  };
33
34
  return (
35
    <div className="flex flex-col h-screen w-full ">
36
      {displayForm ? (
37
        <div
38
          className="fixed top-1/2 left-1/2 z-10
39
        transform -translate-x-1/2 -translate-y-1/2"
40
        >
41
          <LoginForm setDisplayForm={setDisplayForm} />
42
        </div>
43
      ) : null}
44
      <div
45
        style={{
46
          pointerEvents: overlay().click,
47
          filter: overlay().backdrop,
48
        }}
49
      >
50
        <Header setDisplayForm={setDisplayForm} />
51
52
        <div className="mb-auto">
53
          <Routes>
54
            <Route path="/" element={<Home />} />
55
            <Route path="/login/google/failure" element={<LoginFailure />} />
56
            <Route path="/login/google/success" element={<LoginSuccess />}/>
57
            <Route path="/logout/google" element={<Logout />}/>
58
            <Route path="/account" element={<Account />}/>
59
          </Routes>
60
        </div>
61
        <Footer />
62
      </div>
63
    </div>
64
  );
65
};
66
67
export default App;
68