import { useState, useEffect } from "react"; import { Link, useParams } from "react-router-dom"; import { Person } from "../items"; import { apiFetch } from "./api"; import { GameImage } from "./GameImage"; import { LoadingState, EmptyState } from "./components/EmptyState"; export const PersonDetails = () => { const { name } = useParams<{ name: string }>(); const [person, setPerson] = useState(null); const [loading, setLoading] = useState(!!name); const [error, setError] = useState(name ? null : "Person name is missing"); useEffect(() => { if (!name) return; (async () => { try { const res = await apiFetch(`/api/${name}`); if (!res.ok) { throw new Error("Person not found"); } const buffer = await res.arrayBuffer(); setPerson(Person.decode(new Uint8Array(buffer))); } catch (e) { console.error("Failed to decode person:", e); setError(e instanceof Error ? e.message : "Failed to load person data"); } finally { setLoading(false); } })(); }, [name]); if (loading) return ; if (error) return ; if (!person) return ; return (

{person.name}

{person.opinion.length === 0 ? ( ) : (
    {person.opinion.map((op, i) => ( {op.title} ))}
)}
); };