import { useState } from 'react'; import { useNavigate } from 'react-router-dom'; import { useGameStore } from '../store/gameStore'; import { emit, socket, setAuthToken } from '../lib/socket'; import { trackEvent } from '../lib/track'; import NameModal from '../components/NameModal'; import RulesModal from '../components/RulesModal'; export default function GameList() { const navigate = useNavigate(); const games = useGameStore((s) => s.games); const account = useGameStore((s) => s.account); const [showCreate, setShowCreate] = useState(false); const [showRules, setShowRules] = useState(false); const handleShowRules = () => { setShowRules(true); trackEvent('rules_view'); }; const handleLogout = () => { localStorage.removeItem('bridzik_token'); localStorage.removeItem('bridzik_player'); setAuthToken(null); useGameStore.getState().logout(); // Drop the authenticated server-side session for this connection. socket.disconnect(); socket.connect(); navigate('/auth', { replace: true }); }; return (

Bridžik

{account?.username}
{games.length === 0 && (

Žiadne hry. Vytvor prvú!

)} {games.map((g) => { const full = g.players.length >= 4; const isMember = !!account && g.players.some((p) => p.player_id === account.player_id); const canResume = g.started && isMember; const unavailable = !canResume && (full || g.started); const label = canResume ? 'Pokračovať' : full ? 'Plná' : g.started ? 'Začatá' : 'Vstúp'; return (

{g.name}

{g.players.length}/4 hráčov {g.started ? ' · začatá' : ''}

); })}
{showRules && setShowRules(false)} />} {showCreate && setShowCreate(false)} />}
); }