src/components/Sidebar.jsx   A
last analyzed

Complexity

Total Complexity 4
Complexity/F 4

Size

Lines of Code 97
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 69
dl 0
loc 97
rs 10
c 0
b 0
f 0
wmc 4
mnd 3
bc 3
fnc 1
bpm 3
cpm 4
noi 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A Sidebar.jsx ➔ handleResize 0 2 3
1
import React from "react";
2
import { Link, NavLink } from "react-router-dom";
3
import { links } from "../data/data";
4
import { ReactComponent as LogoSpark } from "../assets/LogoSpark.svg";
5
import { useState, useEffect } from "react";
6
const activeLink = "bg-sidebarActive rounded-xl text-blue-300";
7
const normalLink = "text-white";
8
9
const SidebarItems = () => {
10
  return links.map((item) => {
11
    return (
12
      <NavLink
13
        key={item.title}
14
        to={`/${item.title}`}
15
        className={({ isActive }) => (isActive ? activeLink : normalLink)}
16
      >
17
        <div
18
          className="
19
          flex items-center p-2 font-normal text-2xl py-3
20
         hover:bg-sidebarHover rounded-xl transition-colors"
21
        >
22
          <span className="px-3">{item.icon}</span>
23
          <span className="capitalize">{item.title}</span>
24
        </div>
25
      </NavLink>
26
    );
27
  });
28
};
29
30
const compactSidebarItem = () => {
31
  return links.map((item) => {
32
    return (
33
      <NavLink
34
        key={item.title}
35
        to={`/${item.title}`}
36
        className={({ isActive }) => (isActive ? activeLink : normalLink)}
37
      >
38
        <div
39
          className="
40
          flex items-center p-2 font-normal text-2xl py-3
41
         hover:bg-sidebarHover rounded-xl transition-colors"
42
        >
43
          <span className="px-3">{item.icon}</span>
44
        </div>
45
      </NavLink>
46
    );
47
  });
48
};
49
50
const Sidebar = () => {
51
  //const [displaySidebar, setDisplaySidebar] = useState(true);
52
  const [width, setwidth] = useState(window.innerWidth);
53
  useEffect(() => {
54
    function handleResize() {
55
      setwidth(window.innerWidth);
56
    }
57
    window.addEventListener("resize", handleResize);
58
59
    return () => {
60
      window.removeEventListener("resize", handleResize);
61
    };
62
  }, []);
63
64
  if (width < 1536) {
65
    return (
66
      <div className="relative mr-4 w-20 z-10">
67
        <nav
68
          className="
69
            h-screen overflow-auto flex flex-col bg-sidebarBlue p-3 fixed"
70
        >
71
          {/* <div className="pt-2 pb-5">
72
            <LogoSpark />
73
          </div> */}
74
          {compactSidebarItem()}
75
        </nav>
76
      </div>
77
    );
78
  }
79
80
  return (
81
    <div className="relative min-w-80 w-80 mr-4 z-10">
82
      <nav
83
        className="
84
          h-screen overflow-auto flex flex-col
85
          w-72 bg-sidebarBlue p-3 fixed"
86
      >
87
        <div className="pt-2 pb-5">
88
          <LogoSpark />
89
        </div>
90
        {SidebarItems()}
91
      </nav>
92
    </div>
93
  );
94
};
95
96
export default Sidebar;
97