'use client' import { useEffect, useState } from 'react' import type { Game } from '@/types' import GameDetailModal from './GameDetailModal' interface Props { libraryId: string } export default function GamesView({ libraryId }: Props) { const [games, setGames] = useState([]) const [loading, setLoading] = useState(true) const [error, setError] = useState(null) const [selected, setSelected] = useState(null) useEffect(() => { fetch(`/api/games?libraryId=${encodeURIComponent(libraryId)}`) .then((r) => r.json()) .then((data) => { setGames(data) setLoading(false) }) .catch(() => { setError('Failed to load games') setLoading(false) }) }, [libraryId]) if (loading) return if (error) return if (games.length === 0) return return ( <>
{games.map((game) => ( ))}
{selected && ( setSelected(null)} /> )} ) } function LoadingGrid() { return (
{Array.from({ length: 12 }).map((_, i) => (
))}
) } function ErrorMessage({ message }: { message: string }) { return (
{message}
) } function EmptyState() { return (

No games found

Each game should be a folder containing a .zip file.

) }