File size: 4,616 Bytes
cb20bdc aa651ae cb20bdc 2e4a89e 3b85fd7 2e4a89e 3b85fd7 cb20bdc aa651ae cb20bdc 2e4a89e 03769d0 2e4a89e 03769d0 2e4a89e 0879a03 2e4a89e 3b85fd7 2e4a89e 3b85fd7 2e4a89e cb20bdc |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
"use client";
import React, { useState, useEffect } from "react";
import Link from "next/link";
import Image from "next/image";
import { usePathname } from "next/navigation";
import "./Sidebar.css";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import {
faBars,
faCogs,
faHome,
faStar,
faTv,
faFilm,
faBookBookmark,
faCodeCommit,
faBook,
} from "@fortawesome/free-solid-svg-icons";
import config from "@/lib/config";
const Sidebar = () => {
const [isOpen, setIsOpen] = useState(false);
const pathname = usePathname();
const [hoveredLink, setHoveredLink] = useState(null);
const [prevLink, setPrevLink] = useState(null);
useEffect(() => {
const activeLink = document.querySelector(
`.sidebar-link[href="${pathname}"]`
);
if (activeLink) {
setPrevLink(activeLink);
}
}, [pathname]);
const toggleSidebar = () => {
setIsOpen(!isOpen);
};
const handleMouseEnter = (e) => {
setPrevLink(document.querySelector(".sidebar-link.active"));
setHoveredLink(e.target);
};
const handleMouseLeave = () => {
setHoveredLink(null);
};
return (
<div className={`sidebar ${isOpen ? "open" : "closed"}`}>
<div className="sidebar-header">
<button className="sidebar-toggle" onClick={toggleSidebar}>
<FontAwesomeIcon icon={faBars} size="sm" />
</button>
{isOpen && (
<h1 className="sidebar-title">
Nexora{" "}
<Image
className="sidebar-logo"
src="/favicon-32x32.png"
width={32}
height={32}
alt="Nexora Logo"
/>
</h1>
)}
</div>
<div className="sidebar-content">
{isOpen && (
<div className="sidebar-menu">
<Link
href="/"
className={`sidebar-link ${pathname === "/" ? "active" : ""}`}
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
>
<SidebarItem icon={faHome} text="Home" />
</Link>
<Link
href="/movies"
className={`sidebar-link ${
pathname === "/movies" ? "active" : ""
}`}
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
>
<SidebarItem icon={faFilm} text="Movies" />
</Link>
<Link
href="/tvshows"
className={`sidebar-link ${
pathname === "/tvshows" ? "active" : ""
}`}
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
>
<SidebarItem icon={faTv} text="TV Shows" />
</Link>
<Link
href="/new"
className={`sidebar-link ${pathname === "/new" ? "active" : ""}`}
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
>
<SidebarItem icon={faStar} text="New" />
</Link>
<Link
href="/mylist"
className={`sidebar-link ${
pathname === "/mylist" ? "active" : ""
}`}
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
>
<SidebarItem icon={faBookBookmark} text="My List" />
</Link>
</div>
)}
{isOpen && (
<div className="sidebar-footer">
<Link
href="/dashboard"
className={`sidebar-link ${
pathname === "/dashboard" ? "active" : ""
}`}
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
>
<SidebarItem icon={faBook} text="Dashboard" />
</Link>
<Link
href="/settings"
className={`sidebar-link ${
pathname === "/settings" ? "active" : ""
}`}
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
>
<SidebarItem icon={faCogs} text="Settings" />
</Link>
<SidebarItem icon={faCodeCommit} text={config.version} />
</div>
)}
</div>
</div>
);
};
const SidebarItem = ({ icon, text }) => {
return (
<div className="sidebar-item">
<FontAwesomeIcon icon={icon} size="lg" />
<p className="sidebar-item-text">{text}</p>
</div>
);
};
export default Sidebar;
|