From 27744272ecbf999f1ab1be19a09aeb06f9eb4d5c Mon Sep 17 00:00:00 2001 From: Pinapelz Date: Sat, 19 Apr 2025 14:19:16 -0700 Subject: the moekyun special update --- site/src/components/TitleBar.tsx | 124 +++++++++++++++++++++++++++------------ 1 file changed, 85 insertions(+), 39 deletions(-) (limited to 'site/src/components/TitleBar.tsx') diff --git a/site/src/components/TitleBar.tsx b/site/src/components/TitleBar.tsx index 33963b7..b20beae 100644 --- a/site/src/components/TitleBar.tsx +++ b/site/src/components/TitleBar.tsx @@ -1,14 +1,57 @@ -import { Link } from "react-router-dom"; import { useState, useEffect, useRef } from "react"; +import { + Link, + useSearchParams, + useNavigate, + useLocation, +} from "react-router-dom"; interface GameCategory { name: string; games: { id: string; title: string }[]; } - const TitleBar: React.FC = () => { const [dropdownOpen, setDropdownOpen] = useState(false); const dropdownRef = useRef(null); + const [searchParams] = useSearchParams(); + const navigate = useNavigate(); + const location = useLocation(); + const isMoe = searchParams.has("moe"); + + const toggleTheme = () => { + const params = new URLSearchParams(searchParams); + + if (isMoe) { + params.delete("moe"); + localStorage.setItem("theme", "dark"); + } else { + params.set("moe", ""); + localStorage.setItem("theme", "light"); + } + + navigate(`${location.pathname}?${params.toString()}`); + }; + + + useEffect(() => { + const savedTheme = localStorage.getItem("theme"); + + const hasMoe = searchParams.has("moe"); + + if (!hasMoe && savedTheme === "light") { + const params = new URLSearchParams(searchParams); + params.set("moe", ""); + navigate(`${location.pathname}?${params.toString()}`, { replace: true }); + } + + if (hasMoe && savedTheme === "dark") { + const params = new URLSearchParams(searchParams); + params.delete("moe"); + navigate(`${location.pathname}?${params.toString()}`, { replace: true }); + } + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [location.pathname, navigate]); + const gameCategories: GameCategory[] = [ { @@ -16,11 +59,11 @@ const TitleBar: React.FC = () => { games: [ { id: "iidx", title: "beatmania IIDX" }, { id: "sdvx", title: "SOUND VOLTEX" }, - { id: "ddr", title: "DDR"}, - { id: "jubeat", title: "jubeat"}, - { id: "popn_music", title: "pop'n music"}, - { id: "nostalgia", title: "NOSTALGIA"}, - { id: "gitadora", title: "GITADORA"} + { id: "ddr", title: "DDR" }, + { id: "jubeat", title: "jubeat" }, + { id: "popn_music", title: "pop'n music" }, + { id: "nostalgia", title: "NOSTALGIA" }, + { id: "gitadora", title: "GITADORA" }, ], }, { @@ -35,15 +78,11 @@ const TitleBar: React.FC = () => { }, { name: "TAITO", - games: [ - { id: "music_diver", title: "MUSIC DIVER" }, - ], + games: [{ id: "music_diver", title: "MUSIC DIVER" }], }, { name: "BANDAI NAMCO", - games: [ - { id: "taiko", title: "TAIKO" }, - ], + games: [{ id: "taiko", title: "TAIKO" }], }, ]; @@ -56,46 +95,53 @@ const TitleBar: React.FC = () => { setDropdownOpen(false); } }; - - if (dropdownOpen) { + if (dropdownOpen) document.addEventListener("mousedown", handleClickOutside); - } - - return () => { - document.removeEventListener("mousedown", handleClickOutside); - }; + return () => document.removeEventListener("mousedown", handleClickOutside); }, [dropdownOpen]); return ( -
+
+ 573 Updates Logo -
+
573
- - {/* Site Title */} - + UPDATES
- {/* Navigation Section */}
- + All Games - {/* Dropdown Menu */}
{dropdownOpen && ( -
+
{gameCategories.map((category, index) => (
-
+
{category.name}
3 - ? "grid grid-cols-1 sm:grid-cols-2 gap-x-2 gap-y-0.5" - : "space-y-0.5" - }`} + className={`${category.games.length > 3 ? "grid grid-cols-1 sm:grid-cols-2 gap-x-2 gap-y-0.5" : "space-y-0.5"}`} > {category.games.map((game) => ( setDropdownOpen(false)} > {game.title} -- cgit v1.2.3