import { Link, useNavigate } from 'react-router'; import { useAuth } from '../contexts/AuthContext'; import type { SupportedGame } from '../types/game'; import { useState, useEffect } from 'react'; import dancerushImage from '../assets/games/dancerush.webp'; const Home = () => { const { user, isLoading, logout } = useAuth(); const [supportedGames, setSupportedGames] = useState([]); const [gamesLoading, setGamesLoading] = useState(true); const navigate = useNavigate(); const handleLogout = async () => { try { await logout(); navigate('/'); } catch (error) { console.error('Logout failed:', error); alert('Network error during logout. Please try again.'); } }; const getGameImage = (internalName: string) => { switch(internalName){ case "dancerush": { return dancerushImage; } default: { return null } } } useEffect(() => { const fetchSupportedGames = async () => { try { const response = await fetch(import.meta.env.VITE_API_URL+'/supportedGames'); if (!response.ok) { throw new Error('Failed to fetch supported games'); } const data = await response.json(); setSupportedGames(data); } catch (error) { console.error('Failed to fetch supported games:', error); alert('Failed to load supported games. Please refresh the page.'); } finally { setGamesLoading(false); } }; fetchSupportedGames(); }, []); if (isLoading || gamesLoading) { return (

Loading dashboard...

); } if (!user) { return (

Session Expired

Please sign in to access your dashboard.

Sign In Back to Home
); } return (
{/* Navigation */} {/* Main Content */}
{/* Header */}

Dashboard

Track your rhythm game progress and performance

{/* Supported Games */}
{supportedGames.map((game) => (
{getGameImage(game.internalName) !== null ? ( {game.formattedName} ) : (
)}

{game.formattedName}

{game.description}

))}
); }; export default Home;