import { useState, useMemo } from 'react' import { AdminTable, type Column } from '../../components/admin/AdminTable' import { DeleteConfirmModal } from '../../components/admin/DeleteConfirmModal' import { useRuns, useDeleteRun } from '../../hooks/useRuns' import { useGames } from '../../hooks/useGames' import type { NuzlockeRun } from '../../types/game' export function AdminRuns() { const { data: runs = [], isLoading: runsLoading } = useRuns() const { data: games = [], isLoading: gamesLoading } = useGames() const deleteRun = useDeleteRun() const [deleting, setDeleting] = useState(null) const gameMap = useMemo( () => new Map(games.map((g) => [g.id, g.name])), [games], ) const columns: Column[] = [ { header: 'Run Name', accessor: (r) => r.name, sortKey: (r) => r.name }, { header: 'Game', accessor: (r) => gameMap.get(r.gameId) ?? `Game #${r.gameId}`, sortKey: (r) => gameMap.get(r.gameId) ?? '', }, { header: 'Status', accessor: (r) => ( {r.status} ), sortKey: (r) => r.status, }, { header: 'Started', accessor: (r) => new Date(r.startedAt).toLocaleDateString(), sortKey: (r) => r.startedAt, }, ] return (

Runs

r.id} onRowClick={(r) => setDeleting(r)} /> {deleting && ( deleteRun.mutate(deleting.id, { onSuccess: () => setDeleting(null), }) } onCancel={() => setDeleting(null)} isDeleting={deleteRun.isPending} /> )}
) }