import { useState, useEffect } from "react"; import { useParams } from "react-router-dom"; import { Game, Source } from "../items"; import { apiFetch } from "./api"; export function GameDetails() { const { title } = useParams<{ title: string }>(); const [game, setGame] = useState(null); const [loading, setLoading] = useState(true); useEffect(() => { if (!title) return; apiFetch(`/api/game/${encodeURIComponent(title)}`) .then(async (res) => { if (!res.ok) throw new Error("Game not found"); return Game.decode(new Uint8Array(await res.arrayBuffer())); }) .then((data) => { setGame(data); setLoading(false); }) .catch((err) => { console.error(err); setLoading(false); }); }, [title]); if (loading) return
Loading...
; if (!game) return
Game not found
; const getExternalLink = () => { if (game.source === Source.STEAM) { return `https://store.steampowered.com/app/${game.remoteId}`; } else if (game.source === Source.ROBLOX) { return `https://www.roblox.com/games/${game.remoteId}`; } return "#"; }; return (

{game.title}

Source:{" "} {game.source === Source.STEAM ? "Steam" : "Roblox"}
Players: {game.minPlayers} - {game.maxPlayers}
Price: ${game.price}
View on {game.source === Source.STEAM ? "Steam" : "Roblox"}
); }