import React from 'react'; import { Link, useLocation } from "react-router-dom"; import "../App.css" import "./sidebar.css"; import logo from "../imgs/logo.png" import img1 from "../imgs/1.png" import img2 from "../imgs/2.png" import img3 from "../imgs/3.png" import img4 from "../imgs/4.png" import img5 from "../imgs/5.png" import img6 from "../imgs/6.png" import img7 from "../imgs/7.png" import img8 from "../imgs/8.png" import img9 from "../imgs/9.png" import Login from "./login.js" export default function Sidebar(prop) { const {token,setToken} = prop const [profile, setProfile] = React.useState(null); React.useEffect(() => { fetch(`https://lp.ardapektezol.com/api/v1/profile`,{ headers: { 'Content-Type': 'application/json', Authorization: token }}) .then(r => r.json()) .then(d => setProfile(d.data)) }, [token]); // Locks search button for 300ms before it can be clicked again, prevents spam const [isLocked, setIsLocked] = React.useState(false); function HandleLock(arg) { if (!isLocked) { setIsLocked(true); setTimeout(() => setIsLocked(false), 300); SidebarHide(arg) } } // Clicked buttons function SidebarClick(x){ const btn = document.querySelectorAll("button.sidebar-button"); if(sidebar===1){setSidebar(0);SidebarHide()} btn.forEach((e,i) =>{ btn[i].style.backgroundColor="inherit" }) btn[x].style.backgroundColor="#202232" } // The menu button const [sidebar, setSidebar] = React.useState(); function SidebarHide(){ const btn = document.querySelectorAll("button.sidebar-button") const span = document.querySelectorAll("button.sidebar-button>span"); const side = document.querySelector("#sidebar-list"); const login = document.querySelectorAll(".login>button")[1]; if(sidebar===1){ setSidebar(0) side.style.width="320px" btn.forEach((e, i) =>{ e.style.width="310px" setTimeout(() => { span[i].style.opacity="1" login.style.opacity="1" }, 100) }) side.style.zIndex="2" } else { side.style.width="40px"; setSidebar(1) btn.forEach((e,i) =>{ e.style.width="40px" span[i].style.opacity="0" }) login.style.opacity="0" setTimeout(() => { side.style.zIndex="0" }, 300); } } // Links const location = useLocation() React.useEffect(()=>{ if(location.pathname==="/"){SidebarClick(1)} if(location.pathname.includes("news")){SidebarClick(2)} if(location.pathname.includes("records")){SidebarClick(3)} if(location.pathname.includes("leaderboards")){SidebarClick(4)} if(location.pathname.includes("discussions")){SidebarClick(5)} if(location.pathname.includes("scorelog")){SidebarClick(6)} if(location.pathname.includes("profile")){SidebarClick(7)} if(location.pathname.includes("rules")){SidebarClick(9)} if(location.pathname.includes("about")){SidebarClick(10)} // eslint-disable-next-line react-hooks/exhaustive-deps }, [location.pathname]) const [search,setSearch] = React.useState(null) const [searchData,setSearchData] = React.useState(null) React.useEffect(()=>{ fetch(`https://lp.ardapektezol.com/api/v1/search?q=${search}`) .then(r=>r.json()) .then(d=>setSearchData(d.data)) }, [search]) return (
) }