"use client"; import { Trash2Icon } from "lucide-react"; 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"; import { Checkbox } from "@/components/ui/checkbox"; /** * Delete a model, whatever its state (failed, incomplete, ready, …). By default its files are * deleted from disk too (by the worker); unchecked, only the library entry goes. */ export function DeleteModelButton({ id, repoId, localPath, mayHaveFiles, }: { id: string; repoId: string; localPath: string; /** False if nothing was ever downloaded, so there's nothing on disk to ask about. */ mayHaveFiles: boolean; }) { const router = useRouter(); const [deleteFiles, setDeleteFiles] = useState(true); const [pending, setPending] = useState(false); async function remove() { setPending(true); const res = await fetch(`/api/models/${id}${mayHaveFiles && deleteFiles ? "?files=1" : ""}`, { method: "DELETE" }); if (res.ok) { toast.success(res.status === 202 ? `Deleting ${repoId} and its files…` : `${repoId} removed from the library`); router.push("/"); router.refresh(); } else { const body = await res.json().catch(() => ({})); toast.error(body.error?.message ?? `Delete failed (${res.status})`); setPending(false); } } return ( } > Delete Delete {repoId}? {mayHaveFiles ? "The model is removed from the library, including its tags and job history." : "Nothing was downloaded yet, so this only removes the library entry."} {mayHaveFiles && ( )} Cancel {mayHaveFiles && deleteFiles ? "Delete with files" : "Delete"} ); }