diff options
Diffstat (limited to 'frontend/src/components/sidebar.js')
| -rw-r--r-- | frontend/src/components/sidebar.js | 42 |
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 @@ | |||
| 1 | import React from 'react'; | 1 | import React, { useEffect } from 'react'; |
| 2 | import { Link, useLocation } from "react-router-dom"; | 2 | import { Link, useLocation } from "react-router-dom"; |
| 3 | 3 | ||
| 4 | import "../App.css" | 4 | import "../App.css" |
| @@ -18,6 +18,7 @@ import Login from "./login.js" | |||
| 18 | export default function Sidebar(prop) { | 18 | export default function Sidebar(prop) { |
| 19 | const {token,setToken} = prop | 19 | const {token,setToken} = prop |
| 20 | const [profile, setProfile] = React.useState(null); | 20 | const [profile, setProfile] = React.useState(null); |
| 21 | |||
| 21 | React.useEffect(() => { | 22 | React.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 |
| 33 | const [isLocked, setIsLocked] = React.useState(false); | 33 | const [isLocked, setIsLocked] = React.useState(false); |
| 34 | function HandleLock(arg) { | 34 | function HandleLock(arg) { |
| @@ -40,34 +40,38 @@ if (!isLocked) { | |||
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | 42 | ||
| 43 | // The menu button | ||
| 44 | const [sidebar, setSidebar] = React.useState(); | ||
| 45 | |||
| 43 | // Clicked buttons | 46 | // Clicked buttons |
| 44 | function SidebarClick(x){ | 47 | function SidebarClick(x){ |
| 45 | const btn = document.querySelectorAll("button.sidebar-button"); | 48 | const btn = document.querySelectorAll("button.sidebar-button"); |
| 46 | 49 | ||
| 47 | if(sidebar===1){setSidebar(0);SidebarHide()} | 50 | if(sidebar===1){setSidebar(0);SidebarHide()} |
| 48 | 51 | ||
| 52 | // clusterfuck | ||
| 49 | btn.forEach((e,i) =>{ | 53 | btn.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 | }) |
| 52 | btn[x].style.backgroundColor="#202232" | 57 | btn[x].classList.add("sidebar-button-selected") |
| 58 | btn[x].classList.remove("sidebar-button-deselected") | ||
| 53 | 59 | ||
| 54 | } | 60 | } |
| 55 | 61 | ||
| 56 | |||
| 57 | // The menu button | ||
| 58 | const [sidebar, setSidebar] = React.useState(); | ||
| 59 | |||
| 60 | function SidebarHide(){ | 62 | function SidebarHide(){ |
| 61 | const btn = document.querySelectorAll("button.sidebar-button") | 63 | const btn = document.querySelectorAll("button.sidebar-button") |
| 62 | const span = document.querySelectorAll("button.sidebar-button>span"); | 64 | const span = document.querySelectorAll("button.sidebar-button>span"); |
| 63 | const side = document.querySelector("#sidebar-list"); | 65 | const side = document.querySelector("#sidebar-list"); |
| 64 | const login = document.querySelectorAll(".login>button")[1]; | 66 | const login = document.querySelectorAll(".login>button")[1]; |
| 67 | const searchbar = document.querySelector("#searchbar"); | ||
| 65 | 68 | ||
| 66 | if(sidebar===1){ | 69 | if(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 |
| 93 | const location = useLocation() | 99 | const location = useLocation() |
| 94 | React.useEffect(()=>{ | 100 | React.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 | ||
| 108 | const [search,setSearch] = React.useState(null) | 113 | const [search,setSearch] = React.useState(null) |
| 109 | const [searchData,setSearchData] = React.useState(null) | 114 | const [searchData,setSearchData] = React.useState(null) |
| 115 | |||
| 110 | React.useEffect(()=>{ | 116 | React.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 Logs</span></button> | 157 | <button className='sidebar-button'><img src={img7} alt="" /><span>Score Logs</span></button> |
| 156 | </Link> | 158 | </Link> |