aboutsummaryrefslogtreecommitdiff
path: root/frontend/src/components/Sidebar/Sidebar.tsx
diff options
context:
space:
mode:
authorWolfboy248 <georgejvindkarlsen@gmail.com>2025-08-25 09:36:51 +0200
committerWolfboy248 <georgejvindkarlsen@gmail.com>2025-08-25 09:36:51 +0200
commit246eabe4a46d2585d653738e46089ed2bfada8bd (patch)
treec86dd05119b0aa086a5d5401dd6a48d90a6f3bbd /frontend/src/components/Sidebar/Sidebar.tsx
parentReorganised Maplist and Sidebar (diff)
downloadlphub-246eabe4a46d2585d653738e46089ed2bfada8bd.tar.gz
lphub-246eabe4a46d2585d653738e46089ed2bfada8bd.tar.bz2
lphub-246eabe4a46d2585d653738e46089ed2bfada8bd.zip
Restructured sidebar and implemented links var
Diffstat (limited to 'frontend/src/components/Sidebar/Sidebar.tsx')
-rw-r--r--frontend/src/components/Sidebar/Sidebar.tsx82
1 files changed, 33 insertions, 49 deletions
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";
2import { Link, useLocation } from "react-router-dom"; 2import { Link, useLocation } from "react-router-dom";
3import { UserProfile } from "@customTypes/Profile"; 3import { UserProfile } from "@customTypes/Profile";
4 4
5import Header from "./Header"; 5import _Header from "./Header";
6import Footer from "./Footer"; 6import _Footer from "./Footer";
7import Content from "./Content"; 7import _Content from "./Content";
8import _Search from "./Search";
9import links from "./Links";
8 10
9interface SidebarProps { 11interface SidebarProps {
10 setToken: React.Dispatch<React.SetStateAction<string | undefined>>; 12 setToken: React.Dispatch<React.SetStateAction<string | undefined>>;
@@ -19,78 +21,60 @@ const Sidebar: React.FC<SidebarProps> = ({
19 setProfile, 21 setProfile,
20 onUploadRun, 22 onUploadRun,
21}) => { 23}) => {
22 // const [isSidebarLocked, setIsSidebarLocked] = React.useState<boolean>(false); 24 const [isSearching, setIsSearching] = React.useState<boolean>(false);
23 const [isSidebarOpen, setSidebarOpen] = React.useState<boolean>(false); 25 const [isSidebarOpen, setSidebarOpen] = React.useState<boolean>(false);
24 const [selectedButtonIndex, setSelectedButtonIndex] = React.useState<number>(1); 26 const [selectedButtonIndex, setSelectedButtonIndex] = React.useState<number>(1);
25 27
26 const location = useLocation(); 28 const location = useLocation();
27 const path = location.pathname; 29 const path = location.pathname;
28 30
29 const sidebarRef = useRef<HTMLDivElement>(null);
30 const sidebarButtonRefs = useRef<(HTMLButtonElement | null)[]>([]);
31
32 // const _handle_sidebar_toggle = useCallback(() => {
33 // if (!sidebarRef.current) return;
34
35 // if (isSidebarOpen) {
36 // setSidebarOpen(false);
37 // } else {
38 // setSidebarOpen(true);
39 // searchbarRef.current?.focus();
40 // }
41 // }, [isSidebarOpen]);
42
43 const handle_sidebar_click = useCallback( 31 const handle_sidebar_click = useCallback(
44 (clicked_sidebar_idx: number) => { 32 (clicked_sidebar_idx: number) => {
45 setSelectedButtonIndex(clicked_sidebar_idx); 33 setSelectedButtonIndex(clicked_sidebar_idx);
46 if (isSidebarOpen) { 34
47 setSidebarOpen(false); 35 if (clicked_sidebar_idx == 0 && !isSearching) {
36 if (!isSearching) {
37 setIsSearching(true);
38 }
39 } else {
40 setIsSearching(false);
48 } 41 }
49 }, 42 },
50 [isSidebarOpen] 43 [isSearching]
51 ); 44 );
52 45
53 React.useEffect(() => { 46 React.useEffect(() => {
54 if (path === "/") { 47 links.content.forEach((link, i) => {
55 setSelectedButtonIndex(1); 48 if (path.includes(link.to)) {
56 } else if (path.includes("games")) { 49 handle_sidebar_click(i + 1);
57 setSelectedButtonIndex(2); 50 }
58 } else if (path.includes("rankings")) { 51 })
59 setSelectedButtonIndex(3);
60 } else if (path.includes("profile")) {
61 setSelectedButtonIndex(4);
62 } else if (path.includes("rules")) {
63 setSelectedButtonIndex(5);
64 } else if (path.includes("about")) {
65 setSelectedButtonIndex(6);
66 }
67 }, [path]);
68
69 const getButtonClasses = (buttonIndex: number) => {
70 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";
71 const selectedClasses = selectedButtonIndex === buttonIndex ? "bg-primary text-background" : "bg-transparent text-foreground";
72 52
73 return `${baseClasses} ${selectedClasses}`; 53 links.footer.forEach((link, i) => {
74 }; 54 if (path.includes(link.to)) {
55 handle_sidebar_click(links.content.length + i + 1);
56 }
57 })
58 }, [path]);
75 59
76 return ( 60 return (
77 <div className={`w-80 not-md:w-full text-white bg-block flex flex-col not-md:flex-row 61 <div className={`h-screen w-80 not-md:w-full text-white bg-block flex flex-col not-md:flex-row not-md:bg-gradient-to-t not-md:from-block not-md:to-bright
78 }`}> 62 }`}>
79 63
80 {/* Header */} 64 {/* Header */}
81 <Header /> 65 <_Header />
82 66
83 <div className="flex h-full w-full"> 67 <div className="flex flex-1 overflow-hidden w-full not-md:hidden ">
84 <div className="flex flex-col"> 68 <div className={`flex flex-col transition-all duration-300 ${isSearching ? "w-[64px]" : "w-full"}`}>
85 {/* Sidebar Content */} 69 {/* Sidebar Content */}
86 <Content profile={profile} isSidebarOpen={isSidebarOpen} sidebarButtonRefs={sidebarButtonRefs} getButtonClasses={getButtonClasses} handle_sidebar_click={handle_sidebar_click} /> 70 <_Content profile={profile} isSearching={isSearching} selectedButtonIndex={selectedButtonIndex} isSidebarOpen={isSidebarOpen} handle_sidebar_click={handle_sidebar_click} />
87 71
88 {/* Bottom Section */} 72 {/* Bottom Section */}
89 <Footer profile={profile} onUploadRun={onUploadRun} setToken={setToken} setProfile={setProfile} sidebarButtonRefs={sidebarButtonRefs} getButtonClasses={getButtonClasses} handle_sidebar_click={handle_sidebar_click} /> 73 <_Footer profile={profile} isSearching={isSearching} selectedButtonIndex={selectedButtonIndex} onUploadRun={onUploadRun} setToken={setToken} setProfile={setProfile} handle_sidebar_click={handle_sidebar_click} />
90 </div> 74 </div>
91 75
92 <div className="w-20"> 76 <div className={`flex bg-panel ${isSearching ? 'w-full' : "w-0"}`}>
93 77 <_Search profile={profile} isSearching={isSearching} />
94 </div> 78 </div>
95 79
96 </div> 80 </div>