style: format code biome
Local Build and Deploy / deploy (push) Failing after 46s

This commit is contained in:
openhands committed 2026-07-13 21:57:41 +02:00
1 parent 8efd032cc6
commit df38dccbf1
735 files changed
+128321 -120870

No files matched your search

+167 -140
View File
@@ -1,165 +1,192 @@
import Link from "next/link";
import { prisma } from "@/lib/prisma";
import { StatusCard } from "@/components/admin/dashboard";
import { Clock } from "lucide-react";
import Link from "next/link";
import { getTranslations } from "next-intl/server";
import { StatusCard } from "@/components/admin/dashboard";
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;
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", " ") : "\u2014";
return d ? d.toISOString().slice(0, 16).replace("T", " ") : "\u2014";
}
function formatDuration(start: Date, end: Date | null): string {
if (!end) return "\u2014";
const ms = end.getTime() - start.getTime();
if (ms <= 0) return "\u2014";
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`;
if (!end) return "\u2014";
const ms = end.getTime() - start.getTime();
if (ms <= 0) return "\u2014";
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() {
const t = await getTranslations("pages.admin.radio");
const t = await getTranslations("pages.admin.radio");
let history: History[] = [];
let names = new Map<string, string>();
let dbError = false;
let history: History[] = [];
let names = new Map<string, string>();
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,
});
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,
});
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 = [];
}
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 = [];
}
const liveCount = history.filter((h) => !h.endedAt).length;
const peakListeners = history.reduce((max, h) => (h.listenersCount > max ? h.listenersCount : max), 0);
const uniqueDjs = new Set(history.map((h) => String(h.userId))).size;
const liveCount = history.filter((h) => !h.endedAt).length;
const peakListeners = history.reduce(
(max, h) => (h.listenersCount > max ? h.listenersCount : max),
0,
);
const uniqueDjs = new Set(history.map((h) => String(h.userId))).size;
return (
<main>
<nav className="text-xs theme-text-muted dark:theme-text-muted mb-2">
<Link href="/admin/radio">{t("title")}</Link> ·{" "}
<Link href="/admin/radio/settings">{t("settings")}</Link> ·{" "}
<Link href="/admin/radio/banners">{t("banners.title")}</Link> ·{" "}
<Link href="/admin/radio/ranks">{t("ranks")}</Link> ·{" "}
<Link href="/admin/radio/history">{t("history")}</Link>
</nav>
return (
<main>
<nav className="text-xs theme-text-muted dark:theme-text-muted mb-2">
<Link href="/admin/radio">{t("title")}</Link> ·{" "}
<Link href="/admin/radio/settings">{t("settings")}</Link> ·{" "}
<Link href="/admin/radio/banners">{t("banners.title")}</Link> ·{" "}
<Link href="/admin/radio/ranks">{t("ranks")}</Link> ·{" "}
<Link href="/admin/radio/history">{t("history")}</Link>
</nav>
<div className="flex items-center gap-3 mb-6">
<div className="w-10 h-10 rounded-xl bg-gradient-to-br from-[var(--admin-accent)]/20 to-[var(--admin-accent)]/5 grid place-items-center">
<Clock size={20} className="text-[var(--admin-accent)]" />
</div>
<div>
<h1 className="m-0 text-xl font-extrabold text-[var(--admin-text)]">{t("historyPage.title")}</h1>
<p className="m-0 text-xs text-[var(--admin-text-muted)] mt-0.5">{t("historyPage.subtitle")}</p>
</div>
</div>
<div className="flex items-center gap-3 mb-6">
<div className="w-10 h-10 rounded-xl bg-gradient-to-br from-[var(--admin-accent)]/20 to-[var(--admin-accent)]/5 grid place-items-center">
<Clock size={20} className="text-[var(--admin-accent)]" />
</div>
<div>
<h1 className="m-0 text-xl font-extrabold text-[var(--admin-text)]">
{t("historyPage.title")}
</h1>
<p className="m-0 text-xs text-[var(--admin-text-muted)] mt-0.5">
{t("historyPage.subtitle")}
</p>
</div>
</div>
{dbError ? (
<div className="admin-card mb-6">
<p className="text-xs theme-text-muted dark:theme-text-muted m-0">{t("historyPage.dbError")}</p>
</div>
) : (
<div className="grid grid-cols-[repeat(auto-fit,minmax(180px,1fr))] gap-3.5 mb-6">
<StatusCard label={t("historyPage.showsLogged")} value={history.length} icon="\u{1F399}\uFE0F" />
<StatusCard
label={t("historyPage.onAirNow")}
value={liveCount}
state={liveCount > 0 ? "ok" : "neutral"}
icon="\u{1F534}"
/>
<StatusCard label={t("historyPage.uniqueDjs")} value={uniqueDjs} icon="\u{1F9D1}\u200D\u{1F3A4}" />
<StatusCard label={t("historyPage.peakListeners")} value={peakListeners} icon="\u{1F465}" />
</div>
)}
{dbError ? (
<div className="admin-card mb-6">
<p className="text-xs theme-text-muted dark:theme-text-muted m-0">
{t("historyPage.dbError")}
</p>
</div>
) : (
<div className="grid grid-cols-[repeat(auto-fit,minmax(180px,1fr))] gap-3.5 mb-6">
<StatusCard
label={t("historyPage.showsLogged")}
value={history.length}
icon="\u{1F399}\uFE0F"
/>
<StatusCard
label={t("historyPage.onAirNow")}
value={liveCount}
state={liveCount > 0 ? "ok" : "neutral"}
icon="\u{1F534}"
/>
<StatusCard
label={t("historyPage.uniqueDjs")}
value={uniqueDjs}
icon="\u{1F9D1}\u200D\u{1F3A4}"
/>
<StatusCard
label={t("historyPage.peakListeners")}
value={peakListeners}
icon="\u{1F465}"
/>
</div>
)}
{!dbError && history.length === 0 ? <div className="admin-empty">{t("historyPage.empty")}</div> : null}
{!dbError && history.length === 0 ? (
<div className="admin-empty">{t("historyPage.empty")}</div>
) : null}
{history.length > 0 ? (
<section className="mt-6">
<h2 className="admin-section-title">{t("historyPage.showLog", { count: history.length })}</h2>
<table>
<thead>
<tr>
<th>ID</th>
<th>{t("historyPage.colDj")}</th>
<th>{t("historyPage.colShow")}</th>
<th>{t("historyPage.colStarted")}</th>
<th>{t("historyPage.colEnded")}</th>
<th>{t("historyPage.colAirtime")}</th>
<th>{t("historyPage.colListeners")}</th>
<th>{t("historyPage.colNotes")}</th>
</tr>
</thead>
<tbody>
{history.map((h) => (
<tr key={String(h.id)}>
<td>{String(h.id)}</td>
<td>{names.get(String(h.userId)) ?? `#${String(h.userId)}`}</td>
<td>{h.showName ?? "\u2014"}</td>
<td className="text-sm theme-text-muted dark:theme-text-muted whitespace-nowrap">
{formatDate(h.startedAt)}
</td>
<td>
{h.endedAt ? (
<span className="text-sm theme-text-muted dark:theme-text-muted">
{formatDate(h.endedAt)}
</span>
) : (
<span className="inline-block text-[0.72rem] font-bold px-2 py-0.5 rounded-full bg-[var(--admin-success-subtle)] text-[var(--admin-text)]">
{t("historyPage.onAir")}
</span>
)}
</td>
<td className="text-sm theme-text-muted dark:theme-text-muted whitespace-nowrap">
{formatDuration(h.startedAt, h.endedAt)}
</td>
<td>{h.listenersCount}</td>
<td className="text-sm theme-text-muted dark:theme-text-muted whitespace-nowrap">
{h.notes ?? "\u2014"}
</td>
</tr>
))}
</tbody>
</table>
</section>
) : null}
</main>
);
{history.length > 0 ? (
<section className="mt-6">
<h2 className="admin-section-title">
{t("historyPage.showLog", { count: history.length })}
</h2>
<table>
<thead>
<tr>
<th>ID</th>
<th>{t("historyPage.colDj")}</th>
<th>{t("historyPage.colShow")}</th>
<th>{t("historyPage.colStarted")}</th>
<th>{t("historyPage.colEnded")}</th>
<th>{t("historyPage.colAirtime")}</th>
<th>{t("historyPage.colListeners")}</th>
<th>{t("historyPage.colNotes")}</th>
</tr>
</thead>
<tbody>
{history.map((h) => (
<tr key={String(h.id)}>
<td>{String(h.id)}</td>
<td>
{names.get(String(h.userId)) ?? `#${String(h.userId)}`}
</td>
<td>{h.showName ?? "\u2014"}</td>
<td className="text-sm theme-text-muted dark:theme-text-muted whitespace-nowrap">
{formatDate(h.startedAt)}
</td>
<td>
{h.endedAt ? (
<span className="text-sm theme-text-muted dark:theme-text-muted">
{formatDate(h.endedAt)}
</span>
) : (
<span className="inline-block text-[0.72rem] font-bold px-2 py-0.5 rounded-full bg-[var(--admin-success-subtle)] text-[var(--admin-text)]">
{t("historyPage.onAir")}
</span>
)}
</td>
<td className="text-sm theme-text-muted dark:theme-text-muted whitespace-nowrap">
{formatDuration(h.startedAt, h.endedAt)}
</td>
<td>{h.listenersCount}</td>
<td className="text-sm theme-text-muted dark:theme-text-muted whitespace-nowrap">
{h.notes ?? "\u2014"}
</td>
</tr>
))}
</tbody>
</table>
</section>
) : null}
</main>
);
}