import React, { useCallback, useRef } from "react"; import { Link, useLocation } from "react-router-dom"; import { BookIcon, FlagIcon, HelpIcon, HomeIcon, LogoIcon, PortalIcon, SearchIcon, UploadIcon, } from "../images/Images"; import Login from "@components/Login"; import { UserProfile } from "@customTypes/Profile"; import { Search } from "@customTypes/Search"; import { API } from "@api/Api"; interface SidebarProps { setToken: React.Dispatch>; profile?: UserProfile; setProfile: React.Dispatch>; onUploadRun: () => void; } function OpenSidebarIcon() { return ( ) } function ClosedSidebarIcon() { return ( ) } const Sidebar: React.FC = ({ setToken, profile, setProfile, onUploadRun, }) => { const [searchData, setSearchData] = React.useState( undefined ); // const [isSidebarLocked, setIsSidebarLocked] = React.useState(false); const [isSidebarOpen, setSidebarOpen] = React.useState(false); const [selectedButtonIndex, setSelectedButtonIndex] = React.useState(1); const location = useLocation(); const path = location.pathname; const sidebarRef = useRef(null); const searchbarRef = useRef(null); const uploadRunRef = useRef(null); const sidebarButtonRefs = useRef<(HTMLButtonElement | null)[]>([]); const _handle_sidebar_toggle = useCallback(() => { if (!sidebarRef.current) return; if (isSidebarOpen) { setSidebarOpen(false); } else { setSidebarOpen(true); searchbarRef.current?.focus(); } }, [isSidebarOpen]); const handle_sidebar_click = useCallback( (clicked_sidebar_idx: number) => { setSelectedButtonIndex(clicked_sidebar_idx); if (isSidebarOpen) { setSidebarOpen(false); } }, [isSidebarOpen] ); const _handle_search_change = async (q: string) => { const searchResponse = await API.get_search(q); setSearchData(searchResponse); }; React.useEffect(() => { if (path === "/") { setSelectedButtonIndex(1); } else if (path.includes("games")) { setSelectedButtonIndex(2); } else if (path.includes("rankings")) { setSelectedButtonIndex(3); } else if (path.includes("profile")) { setSelectedButtonIndex(4); } else if (path.includes("rules")) { setSelectedButtonIndex(5); } else if (path.includes("about")) { setSelectedButtonIndex(6); } }, [path]); const getButtonClasses = (buttonIndex: number) => { const baseClasses = "flex items-center gap-3 w-full text-left bg-inherit cursor-pointer border-none rounded-lg py-3 px-3 transition-all duration-300 hover:bg-surface1"; const selectedClasses = selectedButtonIndex === buttonIndex ? "bg-primary text-background" : "bg-transparent text-foreground"; return `${baseClasses} ${selectedClasses}`; }; const iconClasses = "w-6 h-6 flex-shrink-0"; return (
Logo {isSidebarOpen && (
PORTAL 2
Least Portals Hub
)}
{/* Sidebar Content */}
{isSidebarOpen && (
Search Search
_handle_search_change(e.target.value)} className="w-full p-2 bg-input text-foreground border border-border rounded-lg text-sm min-w-0" /> {searchData && (
{searchData?.maps.map((q, index) => ( {q.game} {q.chapter} {q.map} ))} {searchData?.players.map((q, index) => ( pfp {q.user_name} ))}
)}
)}
{/* Bottom Section */}
{profile && profile.profile && ( )}
); }; export default Sidebar;