import Link from "next/link"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import AdminPageHeader from "@/components/admin/admin-page-header"; import { deleteMelody } from "@/app/admin/(protected)/melodies/actions"; import { prisma } from "@/lib/db"; type MelodiesPageProps = { searchParams: { error?: string } }; function getErrorMessage(error?: string) { if (error === "invalid-id") return "The selected melody id is invalid."; if (error === "not-found") return "The selected melody no longer exists."; if (error === "delete-failed") return "The melody could not be deleted."; return null; } export default async function MelodiesPage({ searchParams }: MelodiesPageProps) { const melodies = await prisma.melody.findMany({ orderBy: [{ isFeatured: "desc" }, { sortOrder: "asc" }, { updatedAt: "desc" }], include: { category: { select: { nameEn: true, nameAr: true } } }, }); const errorMessage = getErrorMessage(searchParams.error); return (
{errorMessage}
: null} {melodies.length === 0 ? (No melodies yet.
{melody.titleAr}
/{melody.slug}
{melody.category.nameEn} · {melody.category.nameAr}
{melody.durationSec ? `${melody.durationSec}s` : "No duration"} · {melody.isDownloadable ? "Download enabled" : "Streaming only"}