- Convert admin layout, sidebar, and navigation to Tailwind classes - Convert dashboard components (StatusCard, DiagnosticRow, etc.) to Tailwind - Convert all ~48 admin page files from admin CSS classes to Tailwind - Remove unused admin CSS from globals.css (973 → 712 lines) - Convert developers page badges to Tailwind - Remove <style jsx> block from OnlineUsersWidget
266 lines
9.2 KiB
TypeScript
266 lines
9.2 KiB
TypeScript
import Link from 'next/link';
|
|
import { createTrack, deleteTrack, toggleTrack } from '@/actions/admin-radio-autodj';
|
|
import { StatusCard } from '@/components/admin/dashboard';
|
|
import { prisma } from '@/lib/prisma';
|
|
|
|
export const dynamic = 'force-dynamic';
|
|
|
|
export const metadata = { title: 'Radio AutoDJ' };
|
|
|
|
type Track = {
|
|
id: bigint;
|
|
title: string;
|
|
artist: string | null;
|
|
album: string | null;
|
|
artworkUrl: string | null;
|
|
duration: number | null;
|
|
playCount: number;
|
|
lastPlayedAt: Date | null;
|
|
isActive: boolean;
|
|
sortOrder: number;
|
|
};
|
|
|
|
/** Render an integer second count as m:ss, or an em dash when unset. */
|
|
function formatDuration(seconds: number | null): string {
|
|
if (seconds == null || seconds < 0) return '—';
|
|
const m = Math.floor(seconds / 60);
|
|
const s = seconds % 60;
|
|
return `${m}:${String(s).padStart(2, '0')}`;
|
|
}
|
|
|
|
function formatDate(d: Date | null): string {
|
|
return d ? d.toISOString().slice(0, 16).replace('T', ' ') : '—';
|
|
}
|
|
|
|
export default async function AdminRadioAutoDjPage() {
|
|
let tracks: Track[] = [];
|
|
let dbError = false;
|
|
|
|
try {
|
|
tracks = await prisma.radioAutoDjPlaylist
|
|
.findMany({
|
|
select: {
|
|
id: true,
|
|
title: true,
|
|
artist: true,
|
|
album: true,
|
|
artworkUrl: true,
|
|
duration: true,
|
|
playCount: true,
|
|
lastPlayedAt: true,
|
|
isActive: true,
|
|
sortOrder: true,
|
|
},
|
|
orderBy: [{ sortOrder: 'asc' }, { title: 'asc' }],
|
|
})
|
|
.catch(() => {
|
|
dbError = true;
|
|
return [];
|
|
});
|
|
} catch {
|
|
dbError = true;
|
|
tracks = [];
|
|
}
|
|
|
|
const activeCount = tracks.filter((t) => t.isActive).length;
|
|
const inactiveCount = tracks.length - activeCount;
|
|
|
|
return (
|
|
<main>
|
|
<nav className="muted" style={{ marginBottom: '0.5rem' }}>
|
|
<Link href="/admin/radio">Radio</Link> ·{' '}
|
|
<Link href="/admin/radio/settings">Settings</Link> ·{' '}
|
|
<Link href="/admin/radio/banners">Banners</Link> ·{' '}
|
|
<Link href="/admin/radio/ranks">Ranks</Link> ·{' '}
|
|
<Link href="/admin/radio/history">History</Link> ·{' '}
|
|
<Link href="/admin/radio/autodj">AutoDJ</Link>
|
|
</nav>
|
|
|
|
<section className="mt-6">
|
|
<h2>Radio AutoDJ</h2>
|
|
<p className="muted" style={{ marginTop: '-0.4rem' }}>
|
|
Fallback playlist (<code>radio_auto_dj_playlist</code>) the radio rotates
|
|
through when no live DJ is streaming. Ordered by sort order then title.
|
|
</p>
|
|
|
|
{dbError ? (
|
|
<div className="card" style={{ marginBottom: '1.5rem' }}>
|
|
<p className="muted" style={{ margin: 0 }}>
|
|
Could not load the AutoDJ playlist (database unavailable).
|
|
</p>
|
|
</div>
|
|
) : (
|
|
<div className="grid grid-cols-[repeat(auto-fit,minmax(180px,1fr))] gap-3.5 mb-6">
|
|
<StatusCard label="Tracks" value={tracks.length} icon="🎵" />
|
|
<StatusCard
|
|
label="Active"
|
|
value={activeCount}
|
|
state={activeCount > 0 ? 'ok' : 'neutral'}
|
|
icon="▶️"
|
|
/>
|
|
<StatusCard
|
|
label="Inactive"
|
|
value={inactiveCount}
|
|
state={inactiveCount > 0 ? 'warn' : 'neutral'}
|
|
icon="⏸️"
|
|
/>
|
|
</div>
|
|
)}
|
|
</section>
|
|
|
|
<section className="mt-6">
|
|
<h2>Add track</h2>
|
|
<form action={createTrack} className="card">
|
|
<div className="grid cols-2">
|
|
<div>
|
|
<label htmlFor="new_title" style={{ display: 'block', fontWeight: 700 }}>
|
|
Title
|
|
</label>
|
|
<input
|
|
id="new_title"
|
|
name="title"
|
|
placeholder="Track title"
|
|
required
|
|
style={{ width: '100%' }}
|
|
/>
|
|
</div>
|
|
<div>
|
|
<label htmlFor="new_artist" style={{ display: 'block', fontWeight: 700 }}>
|
|
Artist
|
|
</label>
|
|
<input id="new_artist" name="artist" style={{ width: '100%' }} />
|
|
</div>
|
|
<div>
|
|
<label htmlFor="new_album" style={{ display: 'block', fontWeight: 700 }}>
|
|
Album
|
|
</label>
|
|
<input id="new_album" name="album" style={{ width: '100%' }} />
|
|
</div>
|
|
<div>
|
|
<label htmlFor="new_artworkUrl" style={{ display: 'block', fontWeight: 700 }}>
|
|
Artwork URL
|
|
</label>
|
|
<input
|
|
id="new_artworkUrl"
|
|
name="artworkUrl"
|
|
placeholder="https://…/cover.png"
|
|
style={{ width: '100%' }}
|
|
/>
|
|
</div>
|
|
<div>
|
|
<label htmlFor="new_duration" style={{ display: 'block', fontWeight: 700 }}>
|
|
Duration (seconds)
|
|
</label>
|
|
<input
|
|
id="new_duration"
|
|
name="duration"
|
|
type="number"
|
|
min={0}
|
|
placeholder="e.g. 215"
|
|
style={{ width: '100%' }}
|
|
/>
|
|
</div>
|
|
<div>
|
|
<label htmlFor="new_sortOrder" style={{ display: 'block', fontWeight: 700 }}>
|
|
Sort order
|
|
</label>
|
|
<input
|
|
id="new_sortOrder"
|
|
name="sortOrder"
|
|
type="number"
|
|
defaultValue={0}
|
|
style={{ width: '100%' }}
|
|
/>
|
|
</div>
|
|
<div style={{ display: 'flex', alignItems: 'flex-end' }}>
|
|
<label style={{ display: 'inline-flex', gap: '0.4rem', alignItems: 'center' }}>
|
|
<input type="checkbox" name="isActive" value="1" defaultChecked /> Active
|
|
</label>
|
|
</div>
|
|
</div>
|
|
<div style={{ marginTop: '0.75rem' }}>
|
|
<button type="submit" className="btn btn-primary">
|
|
Add track
|
|
</button>
|
|
</div>
|
|
</form>
|
|
</section>
|
|
|
|
<section className="mt-6">
|
|
<h2>Playlist ({tracks.length})</h2>
|
|
{tracks.length === 0 ? (
|
|
<p className="muted">No AutoDJ tracks yet — add one above.</p>
|
|
) : (
|
|
<div style={{ overflowX: 'auto' }}>
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Order</th>
|
|
<th>Title</th>
|
|
<th>Artist</th>
|
|
<th>Album</th>
|
|
<th>Duration</th>
|
|
<th>Plays</th>
|
|
<th>Last played</th>
|
|
<th>Status</th>
|
|
<th>Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{tracks.map((t) => (
|
|
<tr key={String(t.id)}>
|
|
<td className="muted">{t.sortOrder}</td>
|
|
<td>
|
|
<span
|
|
style={{ display: 'inline-flex', gap: '0.5rem', alignItems: 'center' }}
|
|
>
|
|
{t.artworkUrl ? (
|
|
<img
|
|
src={t.artworkUrl}
|
|
alt=""
|
|
width={32}
|
|
height={32}
|
|
style={{ borderRadius: 4, objectFit: 'cover' }}
|
|
/>
|
|
) : null}
|
|
<strong>{t.title}</strong>
|
|
</span>
|
|
</td>
|
|
<td className="muted">{t.artist ?? '—'}</td>
|
|
<td className="muted">{t.album ?? '—'}</td>
|
|
<td className="muted">{formatDuration(t.duration)}</td>
|
|
<td className="muted">{t.playCount}</td>
|
|
<td className="muted">{formatDate(t.lastPlayedAt)}</td>
|
|
<td>
|
|
<span className={`inline-block text-[0.72rem] font-bold px-2 py-0.5 rounded-full ${t.isActive ? 'bg-green-600/20 text-[var(--color-text)]' : 'bg-red-500/22 text-[var(--color-text)]'}`}>
|
|
{t.isActive ? 'active' : 'inactive'}
|
|
</span>
|
|
</td>
|
|
<td>
|
|
<div style={{ display: 'flex', gap: '0.4rem', flexWrap: 'wrap' }}>
|
|
<form action={toggleTrack}>
|
|
<input type="hidden" name="id" value={String(t.id)} />
|
|
<input type="hidden" name="isActive" value={t.isActive ? '0' : '1'} />
|
|
<button type="submit" className="btn">
|
|
{t.isActive ? 'Deactivate' : 'Activate'}
|
|
</button>
|
|
</form>
|
|
<form action={deleteTrack}>
|
|
<input type="hidden" name="id" value={String(t.id)} />
|
|
<button type="submit" className="btn btn-danger">
|
|
Delete
|
|
</button>
|
|
</form>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
))}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
)}
|
|
</section>
|
|
</main>
|
|
);
|
|
}
|