import React from "react"; import { Link, useLocation } from 'react-router-dom'; import { BookIcon, FlagIcon, HelpIcon, HomeIcon, LogoIcon, PortalIcon, SearchIcon, UploadIcon } from '@images/Images'; import { UserProfile } from '@customTypes/Profile'; import sidebar from "@css/Sidebar.module.css"; import { Button, Buttons } from "@customTypes/Sidebar"; import btn from "@css/Button.module.css"; import { abort } from "process"; import Login from "@components/Login"; import { API } from '@api/Api'; import inp from "@css/Input.module.css"; import { Search } from '@customTypes/Search'; interface SidebarProps { setToken: React.Dispatch>; profile?: UserProfile; setProfile: React.Dispatch>; onUploadRun: () => void; }; const Sidebar: React.FC = ({ setToken, profile, setProfile, onUploadRun }) => { const location = useLocation(); const [load, setLoad] = React.useState(false); const [searchData, setSearchData] = React.useState(undefined); const [hasClickedSearch, setHasClickedSearch] = React.useState(false); const [isSearching, setIsSearching] = React.useState(false); const [buttonsList, setButtonsList] = React.useState({ top: [ {img: HomeIcon, text: "Home", url: "/"}, {img: PortalIcon, text: "Games", url: "/games"}, {img: FlagIcon, text: "Rankings", url: "/rankings"} ], bottom: [ {img: BookIcon, text: "Rules", url: "/rules"}, {img: HelpIcon, text: "About LPHUB", url: "/about"} ] }); const _handle_search = () => { if (!hasClickedSearch) { _handle_search_change(""); } setHasClickedSearch(true); setIsSearching(!isSearching); document.querySelector("#searchInput")!.focus(); } const _handle_search_change = async (query: string) => { const response = await API.get_search(query); setSearchData(response); } const _get_index_load = () => { const pathname = window.location.pathname; const btnObj = buttonsList.top.find(obj => obj.url === pathname); let btnIndex = buttonsList.top.findIndex(obj => obj.url === pathname); if (btnIndex != -1) { return btnIndex; } else if (buttonsList.top.findIndex(obj => obj.url === pathname) == -1 && buttonsList.bottom.findIndex(obj => obj.url === pathname) != -1) { btnIndex = buttonsList.bottom.findIndex(obj => obj.url === pathname); return btnIndex + buttonsList.top.length + 1; } else if (load) { return currentBtn; } else { return 0; } } const [currentBtn, setCurrentBtn] = React.useState(_get_index_load); React.useEffect(() => { setCurrentBtn(_get_index_load); setLoad(true); }, [location]) return (
{}} to={"/"}>
PORTAL 2 Least Portals Hub
{buttonsList.top.map((e: any, i: any) => { return }) }
{buttonsList.bottom.map((e: any, i: any) => { return }) }
{_handle_search_change(e.target.value)}} id="searchInput" className={inp.sidebar} type="text" placeholder='Search for map or a player...'/>
{searchData?.maps.map((map, i) => { return {map.game} {map.chapter} {map.map} })} {searchData?.players.map((player, i) => { return {player.user_name} })}
) } export default Sidebar;