import { useEffect, useState } from 'react'; import Link from 'next/link'; import { useRouter } from 'next/router'; import Layout from '../../../components/Layout'; import { useAuth } from '../../../lib/use-auth'; export default function CommunityGames() { const router = useRouter(); const { user } = useAuth(); const [games, setGames] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { const loadGames = async () => { try { const response = await fetch('/api/public/games'); if (response.ok) { const data = await response.json(); setGames(data.games); } else { setError('Failed to load community games.'); } } catch { setError('Failed to load community games.'); } finally { setLoading(false); } }; loadGames(); }, []); return (

Community Games

Custom game systems shared by the community — browse their cards.

{error && (
{error}
)} {loading ? (
) : games.length === 0 ? (

No shared games yet

{user ? 'Share one of your custom games from its game space to see it here.' : 'Sign in and share a custom game to see it here.'}

) : (
{games.map((game) => (
router.push(`/community/games/${game.id}`)} role="link" tabIndex={0} onKeyDown={(e) => e.key === 'Enter' && router.push(`/community/games/${game.id}`)} >

{game.name}

{game.description || 'No description'}

{game.card_count} card{game.card_count === 1 ? '' : 's'} → by {game.author}
))}
)} {user && (

Managing your own games? Head to{' '} My Games.

)}
); }