import Link from 'next/link'; import { prisma } from '@/lib/prisma'; export const dynamic = 'force-dynamic'; type History = { id: bigint; userId: bigint; showName: string | null; startedAt: Date; endedAt: Date | null; listenersCount: number; notes: string | null; }; function formatDate(d: Date | null): string { return d ? d.toISOString().slice(0, 16).replace('T', ' ') : '—'; } /** Human-readable airtime between two timestamps (e.g. "1h 23m"). */ function formatDuration(start: Date, end: Date | null): string { if (!end) return '—'; const ms = end.getTime() - start.getTime(); if (ms <= 0) return '—'; const mins = Math.round(ms / 60000); const h = Math.floor(mins / 60); const m = mins % 60; return h > 0 ? `${h}h ${m}m` : `${m}m`; } export default async function AdminRadioHistoryPage() { let history: History[] = []; let names = new Map(); let dbError = false; try { history = await prisma.radioHistory.findMany({ select: { id: true, userId: true, showName: true, startedAt: true, endedAt: true, listenersCount: true, notes: true, }, orderBy: { startedAt: 'desc' }, take: 100, }); // Resolve DJ usernames (users.id is Int, radio_history.user_id is BigInt). const ids = Array.from(new Set(history.map((h) => Number(h.userId)))).filter( (n) => Number.isFinite(n) && n > 0, ); if (ids.length > 0) { const users = await prisma.user.findMany({ where: { id: { in: ids } }, select: { id: true, username: true }, }); names = new Map(users.map((u) => [String(u.id), u.username])); } } catch { dbError = true; history = []; } return (

Radio Play History

Past DJ shows and airtime (radio_history), most recent first. Read-only log of who was on air, when, and how many listeners tuned in.

{dbError ? (

Could not load radio history (database unavailable).

) : null} {history.length === 0 ? (

No radio history recorded.

) : ( {history.map((h) => ( ))}
ID DJ Show Started Ended Airtime Listeners Notes
{String(h.id)} {names.get(String(h.userId)) ?? `#${String(h.userId)}`} {h.showName ?? '—'} {formatDate(h.startedAt)} {formatDate(h.endedAt)} {formatDuration(h.startedAt, h.endedAt)} {h.listenersCount} {h.notes ?? '—'}
)}
); }