aboutsummaryrefslogtreecommitdiff
path: root/frontend/src/components/sidebar.js
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/src/components/sidebar.js')
-rw-r--r--frontend/src/components/sidebar.js42
1 files changed, 22 insertions, 20 deletions
diff --git a/frontend/src/components/sidebar.js b/frontend/src/components/sidebar.js
index 29859ab..6777867 100644
--- a/frontend/src/components/sidebar.js
+++ b/frontend/src/components/sidebar.js
@@ -1,4 +1,4 @@
1import React from 'react'; 1import React, { useEffect } from 'react';
2import { Link, useLocation } from "react-router-dom"; 2import { Link, useLocation } from "react-router-dom";
3 3
4import "../App.css" 4import "../App.css"
@@ -18,6 +18,7 @@ import Login from "./login.js"
18export default function Sidebar(prop) { 18export default function Sidebar(prop) {
19const {token,setToken} = prop 19const {token,setToken} = prop
20const [profile, setProfile] = React.useState(null); 20const [profile, setProfile] = React.useState(null);
21
21React.useEffect(() => { 22React.useEffect(() => {
22 fetch(`https://lp.ardapektezol.com/api/v1/profile`,{ 23 fetch(`https://lp.ardapektezol.com/api/v1/profile`,{
23 headers: { 24 headers: {
@@ -28,7 +29,6 @@ React.useEffect(() => {
28 .then(d => setProfile(d.data)) 29 .then(d => setProfile(d.data))
29 }, [token]); 30 }, [token]);
30 31
31
32// Locks search button for 300ms before it can be clicked again, prevents spam 32// Locks search button for 300ms before it can be clicked again, prevents spam
33const [isLocked, setIsLocked] = React.useState(false); 33const [isLocked, setIsLocked] = React.useState(false);
34function HandleLock(arg) { 34function HandleLock(arg) {
@@ -40,34 +40,38 @@ if (!isLocked) {
40} 40}
41 41
42 42
43// The menu button
44const [sidebar, setSidebar] = React.useState();
45
43// Clicked buttons 46// Clicked buttons
44function SidebarClick(x){ 47function SidebarClick(x){
45const btn = document.querySelectorAll("button.sidebar-button"); 48const btn = document.querySelectorAll("button.sidebar-button");
46 49
47if(sidebar===1){setSidebar(0);SidebarHide()} 50if(sidebar===1){setSidebar(0);SidebarHide()}
48 51
52// clusterfuck
49btn.forEach((e,i) =>{ 53btn.forEach((e,i) =>{
50 btn[i].style.backgroundColor="inherit" 54 btn[i].classList.remove("sidebar-button-selected")
55 btn[i].classList.add("sidebar-button-deselected")
51}) 56})
52btn[x].style.backgroundColor="#202232" 57btn[x].classList.add("sidebar-button-selected")
58btn[x].classList.remove("sidebar-button-deselected")
53 59
54} 60}
55 61
56
57// The menu button
58const [sidebar, setSidebar] = React.useState();
59
60function SidebarHide(){ 62function SidebarHide(){
61const btn = document.querySelectorAll("button.sidebar-button") 63const btn = document.querySelectorAll("button.sidebar-button")
62const span = document.querySelectorAll("button.sidebar-button>span"); 64const span = document.querySelectorAll("button.sidebar-button>span");
63const side = document.querySelector("#sidebar-list"); 65const side = document.querySelector("#sidebar-list");
64const login = document.querySelectorAll(".login>button")[1]; 66const login = document.querySelectorAll(".login>button")[1];
67const searchbar = document.querySelector("#searchbar");
65 68
66if(sidebar===1){ 69if(sidebar===1){
67 setSidebar(0) 70 setSidebar(0)
68 side.style.width="320px" 71 side.style.width="320px"
69 btn.forEach((e, i) =>{ 72 btn.forEach((e, i) =>{
70 e.style.width="310px" 73 e.style.width="310px"
74 e.style.padding = "0.4em 0 0 11px"
71 setTimeout(() => { 75 setTimeout(() => {
72 span[i].style.opacity="1" 76 span[i].style.opacity="1"
73 login.style.opacity="1" 77 login.style.opacity="1"
@@ -77,28 +81,29 @@ if(sidebar===1){
77 side.style.zIndex="2" 81 side.style.zIndex="2"
78} else { 82} else {
79 side.style.width="40px"; 83 side.style.width="40px";
84 searchbar.focus();
85 setSearch(searchbar.value)
80 setSidebar(1) 86 setSidebar(1)
81 btn.forEach((e,i) =>{ 87 btn.forEach((e,i) =>{
82 e.style.width="40px" 88 e.style.width="40px"
89 e.style.padding = "0.4em 0 0 5px"
83 span[i].style.opacity="0" 90 span[i].style.opacity="0"
84 }) 91 })
85 login.style.opacity="0" 92 login.style.opacity="0"
86 setTimeout(() => { 93 setTimeout(() => {
87 side.style.zIndex="0" 94 side.style.zIndex="0"
88 }, 300); 95 }, 300);
89 } 96 }
90} 97}
91
92// Links 98// Links
93const location = useLocation() 99const location = useLocation()
94React.useEffect(()=>{ 100React.useEffect(()=>{
95 if(location.pathname==="/"){SidebarClick(1)} 101 if(location.pathname==="/"){SidebarClick(1)}
96 if(location.pathname.includes("news")){SidebarClick(2)} 102 if(location.pathname.includes("news")){SidebarClick(2)}
97 if(location.pathname.includes("records")){SidebarClick(3)} 103 if(location.pathname.includes("games")){SidebarClick(3)}
98 if(location.pathname.includes("leaderboards")){SidebarClick(4)} 104 if(location.pathname.includes("leaderboards")){SidebarClick(4)}
99 if(location.pathname.includes("discussions")){SidebarClick(5)} 105 if(location.pathname.includes("scorelog")){SidebarClick(5)}
100 if(location.pathname.includes("scorelog")){SidebarClick(6)} 106 if(location.pathname.includes("profile")){SidebarClick(6)}
101 if(location.pathname.includes("profile")){SidebarClick(7)}
102 if(location.pathname.includes("rules")){SidebarClick(9)} 107 if(location.pathname.includes("rules")){SidebarClick(9)}
103 if(location.pathname.includes("about")){SidebarClick(10)} 108 if(location.pathname.includes("about")){SidebarClick(10)}
104 109
@@ -107,6 +112,7 @@ React.useEffect(()=>{
107 112
108const [search,setSearch] = React.useState(null) 113const [search,setSearch] = React.useState(null)
109const [searchData,setSearchData] = React.useState(null) 114const [searchData,setSearchData] = React.useState(null)
115
110React.useEffect(()=>{ 116React.useEffect(()=>{
111 fetch(`https://lp.ardapektezol.com/api/v1/search?q=${search}`) 117 fetch(`https://lp.ardapektezol.com/api/v1/search?q=${search}`)
112 .then(r=>r.json()) 118 .then(r=>r.json())
@@ -139,18 +145,14 @@ return (
139 <button className='sidebar-button'><img src={img3} alt="" /><span>News</span></button> 145 <button className='sidebar-button'><img src={img3} alt="" /><span>News</span></button>
140 </Link> 146 </Link>
141 147
142 <Link to="/records" tabIndex={-1}> 148 <Link to="/games" tabIndex={-1}>
143 <button className='sidebar-button'><img src={img4} alt="" /><span>Records</span></button> 149 <button className='sidebar-button'><img src={img4} alt="" /><span>Games</span></button>
144 </Link> 150 </Link>
145 151
146 <Link to="/leaderboards" tabIndex={-1}> 152 <Link to="/leaderboards" tabIndex={-1}>
147 <button className='sidebar-button'><img src={img5} alt="" /><span>Leaderboards</span></button> 153 <button className='sidebar-button'><img src={img5} alt="" /><span>Leaderboards</span></button>
148 </Link> 154 </Link>
149 155
150 <Link to="/discussions" tabIndex={-1}>
151 <button className='sidebar-button'><img src={img6} alt="" /><span>Discussions</span></button>
152 </Link>
153
154 <Link to="/scorelog" tabIndex={-1}> 156 <Link to="/scorelog" tabIndex={-1}>
155 <button className='sidebar-button'><img src={img7} alt="" /><span>Score&nbsp;Logs</span></button> 157 <button className='sidebar-button'><img src={img7} alt="" /><span>Score&nbsp;Logs</span></button>
156 </Link> 158 </Link>