src/components/Header.jsx   A
last analyzed

Complexity

Total Complexity 2
Complexity/F 0

Size

Lines of Code 72
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 57
mnd 2
bc 2
fnc 0
dl 0
loc 72
rs 10
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
1
import React from "react";
2
import { useLocation } from "react-router-dom";
3
import LogoBlack from "../assets/LogoBlack.svg";
4
import { useStateContext } from "../contexts/ContextProvider";
5
import auth from "../models/auth.js";
6
import { useNavigate } from "react-router-dom";
7
const Header = ({ setDisplayForm }) => {
8
  const navigate = useNavigate();
9
  const { isLoggedIn, setIsLoggedIn } = useStateContext();
10
  console.log(isLoggedIn);
11
  const logout = async () => {
12
    await auth.logout();
13
    await auth.googleLogout();
14
    setIsLoggedIn(false);
15
    navigate("/");
16
  };
17
  return (
18
    <div className="flex w-full flex-row justify-between">
19
      <div className="p-5">
20
        <img src={LogoBlack} alt="Sparkrentals Logo" className="w-64" />
21
      </div>
22
      <nav className="text-2xl font-semibold">
23
        <button
24
          onClick={(event) => (window.location.href = "/")}
25
          className="p-2 m-2"
26
        >
27
          Home
28
        </button>
29
        <button
30
          onClick={(event) => (window.location.href = "/about")}
31
          className="p-2 m-2"
32
        >
33
          About
34
        </button>
35
        {isLoggedIn ? (
36
          <button
37
            onClick={(event) => (window.location.href = "/account")}
38
            className="p-2 m-2"
39
          >
40
            Account
41
          </button>
42
        ) : (
43
          <></>
44
        )}
45
        {isLoggedIn ? (
46
          <button
47
            onClick={() => {
48
              logout();
49
            }}
50
            className="px-3 py-1 m-4 border border-DarkBlue rounded-lg
51
        hover:bg-DarkBlue hover:text-white transition-all"
52
          >
53
            Logout
54
          </button>
55
        ) : (
56
          <button
57
            onClick={() => {
58
              setDisplayForm(true);
59
            }}
60
            className="px-3 py-1 m-4 border border-DarkBlue rounded-lg
61
      hover:bg-DarkBlue hover:text-white transition-all"
62
          >
63
            Login
64
          </button>
65
        )}
66
      </nav>
67
    </div>
68
  );
69
};
70
71
export default Header;
72