"use client"; import { useRouter } from "next/navigation"; import { useState } from "react"; import { toast } from "sonner"; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger, } from "@/components/ui/alert-dialog"; import { Button } from "@/components/ui/button"; /** Removes a not-yet-downloaded model from the library (DB only, no files exist yet). */ export function RemoveModelButton({ id }: { id: string }) { const router = useRouter(); const [busy, setBusy] = useState(false); async function remove() { setBusy(true); const res = await fetch(`/api/models/${id}`, { method: "DELETE" }); if (res.ok) { toast.success("Removed from library"); router.push("/"); router.refresh(); } else { const body = await res.json().catch(() => ({})); toast.error(body.error?.message ?? `Remove failed (${res.status})`); setBusy(false); } } return ( }>Remove Remove from library? Nothing has been downloaded yet, so this only removes the entry. Cancel Remove ); }