From 4a19c64dee68604f742227a88c746dcc1c9ca88e Mon Sep 17 00:00:00 2001 From: Pinapelz Date: Mon, 4 Nov 2024 10:27:09 -0800 Subject: fix build: use Link to navigate to / --- src/components/TitleBar/TitleBar.tsx | 375 +++++++++++++++++------------------ 1 file changed, 178 insertions(+), 197 deletions(-) diff --git a/src/components/TitleBar/TitleBar.tsx b/src/components/TitleBar/TitleBar.tsx index d5c7103..04ead84 100644 --- a/src/components/TitleBar/TitleBar.tsx +++ b/src/components/TitleBar/TitleBar.tsx @@ -2,224 +2,205 @@ import type React from "react"; import "../TitleBar/TitleBarStyle.css"; import { - faHouse, - faBars, - faTimes, - faChevronDown, - faChevronUp, - faSpinner, + faHouse, + faBars, + faTimes, + faChevronDown, + faChevronUp, + faSpinner, } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { useState, useEffect } from "react"; import Link from "next/link"; interface TitleBarProps { - title: string; - redirectUrl?: string; - showHomeButton?: boolean; - backgroundColor?: string; + title: string; + redirectUrl?: string; + showHomeButton?: boolean; + backgroundColor?: string; } const TitleBar: React.FC = ({ - title, - redirectUrl, - showHomeButton, - backgroundColor, + title, + redirectUrl, + showHomeButton, + backgroundColor, }) => { - const hideFromSidebar = ["Fuura Yuri"]; // List of names to hide (e.g., due to graduation) - const [isSidebarOpen, setIsSidebarOpen] = useState(false); - const [isMounted, setIsMounted] = useState(false); - const [groupingData, setPhaseData] = useState<{ - [key: string]: string[]; - } | null>(null); - const [collapsedSections, setCollapsedSections] = useState<{ - [key: string]: boolean; - }>({}); - const [loadingMember, setLoadingMember] = useState(null); + const hideFromSidebar = ["Fuura Yuri"]; // List of names to hide (e.g., due to graduation) + const [isSidebarOpen, setIsSidebarOpen] = useState(false); + const [isMounted, setIsMounted] = useState(false); + const [groupingData, setPhaseData] = useState<{ + [key: string]: string[]; + } | null>(null); + const [collapsedSections, setCollapsedSections] = useState<{ + [key: string]: boolean; + }>({}); + const [loadingMember, setLoadingMember] = useState(null); - useEffect(() => { - setIsMounted(true); - const fetchPhaseData = async () => { - const apiUrl = process.env.NEXT_PUBLIC_API_URL_TESTING; - try { - const response = await fetch(apiUrl + "/api/groups"); - const data = await response.json(); - setPhaseData(data); - const initialCollapsedState = Object.keys(data).reduce( - (acc, phase) => { - acc[phase] = true; - return acc; - }, - {} as { [key: string]: boolean }, - ); - setCollapsedSections(initialCollapsedState); - } catch (error) { - console.error("Error fetching phase data:", error); - } - }; + useEffect(() => { + setIsMounted(true); + const fetchPhaseData = async () => { + const apiUrl = process.env.NEXT_PUBLIC_API_URL_TESTING; + try { + const response = await fetch(apiUrl + "/api/groups"); + const data = await response.json(); + setPhaseData(data); + const initialCollapsedState = Object.keys(data).reduce( + (acc, phase) => { + acc[phase] = true; + return acc; + }, + {} as { [key: string]: boolean }, + ); + setCollapsedSections(initialCollapsedState); + } catch (error) { + console.error("Error fetching phase data:", error); + } + }; - fetchPhaseData(); - }, []); + fetchPhaseData(); + }, []); - const toggleSidebar = () => { - setIsSidebarOpen(!isSidebarOpen); - }; + const toggleSidebar = () => { + setIsSidebarOpen(!isSidebarOpen); + }; - const toggleSection = (phase: string) => { - setCollapsedSections((prevState) => ({ - ...prevState, - [phase]: !prevState[phase], - })); - }; + const toggleSection = (phase: string) => { + setCollapsedSections((prevState) => ({ + ...prevState, + [phase]: !prevState[phase], + })); + }; - const handleMemberClick = (member: string) => { - setLoadingMember(member); - }; + const handleMemberClick = (member: string) => { + setLoadingMember(member); + }; - if (!isMounted) { - return null; - } + if (!isMounted) { + return null; + } - return ( - <> -
+
+
+ + + -
- - - - {title} - - - {showHomeButton && ( - - - - )} -
-
+ {title} + + + {showHomeButton && ( + + + + )} +
+
- {/* Sidebar */} -
-
- PhaseTracker -
-
    - -
  • - Home -
  • - - -
  • - About -
  • - - -
  • - Data -
  • - -
+ {/* Sidebar */} +
+
+ PhaseTracker +
+
    + +
  • + Home +
  • + + +
  • + About +
  • + + +
  • + Data +
  • + +
- -
- {isSidebarOpen && ( +
    + {groupingData ? ( + Object.entries(groupingData).map(([group, members]) => ( +
  • - )} - - ); + className="flex justify-between items-center cursor-pointer select-none" + onClick={() => toggleSection(group)} + > + {group} + +
+ {!collapsedSections[group] && ( + + )} + + )) + ) : ( +
  • Loading...
  • + )} + + + {isSidebarOpen && ( +
    + )} + + ); }; export default TitleBar; -- cgit v1.2.3