import { actions } from "astro:actions" import { LoaderCircle, Trash2 } from "lucide-react" import { useRef, useState } from "react" import { showToast } from "../lib/toast" interface Props { cardId: string recordCid: string rkey: string } export default function DeleteImageButton({ cardId, recordCid, rkey }: Props) { const dialog = useRef(null) const [isDeleting, setIsDeleting] = useState(false) async function deleteImage() { setIsDeleting(true) try { const { error } = await actions.images.delete({ recordCid, rkey }) if (error) { showToast("error", error.message) return } dialog.current?.close() document.getElementById(cardId)?.remove() showToast("success", "Image deleted") } catch { showToast("error", "Could not delete image") } finally { setIsDeleting(false) } } return ( <> isDeleting && event.preventDefault()} >

Delete this image?

This deletes the image from your PDS and cannot be undone.

) }