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[] = [ { name: "KONAMI", 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" }, ], }, { name: "SEGA", games: [ { id: "chunithm_jp", title: "CHUNITHM (JAPAN)" }, { id: "chunithm_intl", title: "CHUNITHM (INTL)" }, { id: "maimaidx_jp", title: "maimai DX (JAPAN)" }, { id: "maimaidx_intl", title: "maimai DX (INTL)" }, { id: "ongeki_jp", title: "O.N.G.E.K.I" }, ], }, { name: "TAITO", games: [{ id: "music_diver", title: "MUSIC DIVER" }], }, { name: "BANDAI NAMCO", games: [{ id: "taiko", title: "TAIKO" }], }, ]; useEffect(() => { const handleClickOutside = (event: MouseEvent) => { if ( dropdownRef.current && !dropdownRef.current.contains(event.target as Node) ) { setDropdownOpen(false); } }; if (dropdownOpen) document.addEventListener("mousedown", handleClickOutside); return () => document.removeEventListener("mousedown", handleClickOutside); }, [dropdownOpen]); return (
573 Updates Logo
573
UPDATES
All Games
{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"}`} > {category.games.map((game) => ( setDropdownOpen(false)} > {game.title} ))}
))}
)}
); }; export default TitleBar;