From 246eabe4a46d2585d653738e46089ed2bfada8bd Mon Sep 17 00:00:00 2001 From: Wolfboy248 Date: Mon, 25 Aug 2025 09:36:51 +0200 Subject: Restructured sidebar and implemented links var --- frontend/src/components/Sidebar/Sidebar.tsx | 82 ++++++++++++----------------- 1 file changed, 33 insertions(+), 49 deletions(-) (limited to 'frontend/src/components/Sidebar/Sidebar.tsx') diff --git a/frontend/src/components/Sidebar/Sidebar.tsx b/frontend/src/components/Sidebar/Sidebar.tsx index 2dafa2b..1d58d2e 100644 --- a/frontend/src/components/Sidebar/Sidebar.tsx +++ b/frontend/src/components/Sidebar/Sidebar.tsx @@ -2,9 +2,11 @@ import React, { useCallback, useRef } from "react"; import { Link, useLocation } from "react-router-dom"; import { UserProfile } from "@customTypes/Profile"; -import Header from "./Header"; -import Footer from "./Footer"; -import Content from "./Content"; +import _Header from "./Header"; +import _Footer from "./Footer"; +import _Content from "./Content"; +import _Search from "./Search"; +import links from "./Links"; interface SidebarProps { setToken: React.Dispatch>; @@ -19,78 +21,60 @@ const Sidebar: React.FC = ({ setProfile, onUploadRun, }) => { - // const [isSidebarLocked, setIsSidebarLocked] = React.useState(false); + const [isSearching, setIsSearching] = 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 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); + + if (clicked_sidebar_idx == 0 && !isSearching) { + if (!isSearching) { + setIsSearching(true); + } + } else { + setIsSearching(false); } }, - [isSidebarOpen] + [isSearching] ); 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-[2000px] py-3 px-3 transition-all duration-300 hover:bg-panel"; - const selectedClasses = selectedButtonIndex === buttonIndex ? "bg-primary text-background" : "bg-transparent text-foreground"; + links.content.forEach((link, i) => { + if (path.includes(link.to)) { + handle_sidebar_click(i + 1); + } + }) - return `${baseClasses} ${selectedClasses}`; - }; + links.footer.forEach((link, i) => { + if (path.includes(link.to)) { + handle_sidebar_click(links.content.length + i + 1); + } + }) + }, [path]); return ( -
{/* Header */} -
+ <_Header /> -
-
+
+
{/* Sidebar Content */} - + <_Content profile={profile} isSearching={isSearching} selectedButtonIndex={selectedButtonIndex} isSidebarOpen={isSidebarOpen} handle_sidebar_click={handle_sidebar_click} /> {/* Bottom Section */} -
+ <_Footer profile={profile} isSearching={isSearching} selectedButtonIndex={selectedButtonIndex} onUploadRun={onUploadRun} setToken={setToken} setProfile={setProfile} handle_sidebar_click={handle_sidebar_click} />
-
- +
+ <_Search profile={profile} isSearching={isSearching} />
-- cgit v1.2.3