Spaces:
Sleeping
Sleeping
File size: 4,994 Bytes
fced295 92f01f5 fced295 b780a2e 784b5c6 fced295 784b5c6 92f01f5 fced295 784b5c6 fced295 784b5c6 fced295 b780a2e 784b5c6 b780a2e 784b5c6 b780a2e 784b5c6 fced295 784b5c6 fced295 784b5c6 fced295 784b5c6 fced295 784b5c6 fced295 784b5c6 b780a2e fced295 b780a2e 784b5c6 fced295 784b5c6 fced295 784b5c6 |
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 |
"use client";
import { VERSION } from "@/lib/config";
import { usePathname } from "next/navigation";
import { Bars3Icon, UserCircleIcon, Cog6ToothIcon, QuestionMarkCircleIcon, BoltIcon } from "@heroicons/react/20/solid";
import Link from "next/link";
import { useEffect, useState, useRef } from "react";
import Image from "next/image";
import logo from "@assets/logo.png";
export default function Sidebar() {
const pathname = usePathname();
const [accessLevel, setAccessLevel] = useState(null);
const [isCollapsed, setIsCollapsed] = useState(true);
const sidebarRef = useRef(null);
const toggleSidebar = () => {
setIsCollapsed(!isCollapsed);
};
useEffect(() => {
setAccessLevel(localStorage.getItem("a_l"));
const handleClickOutside = (event) => {
if (sidebarRef.current && !sidebarRef.current.contains(event.target)) {
setIsCollapsed(true);
}
};
document.addEventListener("mousedown", handleClickOutside);
return () => document.removeEventListener("mousedown", handleClickOutside);
}, []);
const logoStyle = {
width: isCollapsed ? "60px" : "150px",
height: isCollapsed ? "60px" : "150px",
borderRadius: "50px",
transition: "width 0.3s ease, height 0.3s ease",
marginBottom: 0,
marginTop: "20px",
};
const sidebarStyle = {
width: "180px",
left: isCollapsed ? "-180px" : "0",
backgroundColor: "var(--sidebar-background)",
color: "var(--foreground)",
padding: isCollapsed ? "15px" : "20px",
position: "fixed",
height: "100vh",
display: "flex",
flexDirection: "column",
borderRight: "1px solid rgba(255, 255, 255, 0.1)",
transition: "left 0.3s ease, width 0.3s ease, padding 0.3s ease",
zIndex: 10,
};
const versionStyle = {
color: "var(--hover-accent)",
fontSize: isCollapsed ? "0.6em" : "0.9em",
marginTop: "20px",
textAlign: "end",
};
const navLinkStyle = {
display: "flex",
alignItems: "center",
gap: "5px",
padding: "10px 5px",
transition: "all 0.3s ease",
color: "var(--foreground)",
fontSize: "1em",
};
const activeNavLinkStyle = {
backgroundColor: "var(--hover-accent)",
borderRadius: "5px",
animation: "fadeIn .5s ease-in-out, pulse .5s ease-in-out",
};
const textStyle = {
opacity: isCollapsed ? 0 : 1,
transition: "opacity 0.3s ease",
pointerEvents: isCollapsed ? "none" : "auto",
};
const iconStyle = {
width: "30px",
height: "30px",
flexShrink: 0,
};
const toggleButtonStyle = {
position: "absolute",
top: "20px",
right: isCollapsed ? "-50px" : "10px",
width: "35px",
height: "35px",
backgroundColor: "var(--button-background)",
color: "var(--foreground)",
border: "none",
borderRadius: "10px",
cursor: "pointer",
display: "flex",
alignItems: "center",
justifyContent: "center",
boxShadow: "0 2px 5px rgba(0, 0, 0, 0.2)",
transition: "background-color 0.3s ease, right 0.3s ease",
};
return (
<div ref={sidebarRef} className="sidebar-container" style={sidebarStyle}>
<div className="logo-container" style={{ display: "flex", flexDirection: "column", alignItems: "center" }}>
<Image style={logoStyle} src={logo} alt="App Logo" />
<sup style={versionStyle}>{VERSION}</sup>
<button
style={toggleButtonStyle}
onClick={() => toggleSidebar(!isCollapsed)}
>
<Bars3Icon style={{ transform: `rotate(${isCollapsed ? 0 : 90}deg)`, transition: "transform .3s", width: "20px" }} />
</button>
</div>
<ul className="nav-links" style={{ listStyleType: "none", marginTop: "20px", paddingLeft: "0" }}>
<li>
<Link href="/" legacyBehavior>
<a style={{ ...navLinkStyle, ...(pathname === "/" && activeNavLinkStyle) }}>
<UserCircleIcon style={iconStyle} />
<span style={textStyle}>Profile</span>
</a>
</Link>
</li>
<li>
<Link href={`/su/${accessLevel}`} legacyBehavior>
<a style={{ ...navLinkStyle, ...(pathname === `/su/${accessLevel}` && activeNavLinkStyle) }}>
<BoltIcon style={iconStyle} />
<span style={textStyle}>{accessLevel}</span>
</a>
</Link>
</li>
<li>
<Link href="/settings" legacyBehavior>
<a style={{ ...navLinkStyle, ...(pathname === "/settings" && activeNavLinkStyle) }}>
<Cog6ToothIcon style={iconStyle} />
<span style={textStyle}>Settings</span>
</a>
</Link>
</li>
<li>
<Link href="/support" legacyBehavior>
<a style={{ ...navLinkStyle, ...(pathname === "/support" && activeNavLinkStyle) }}>
<QuestionMarkCircleIcon style={iconStyle} />
<span style={textStyle}>Support</span>
</a>
</Link>
</li>
</ul>
</div>
);
}
|