import { startTransition, useEffect, useState } from "react" import { Button } from "@/components/ui/button" import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger } from "@/components/ui/dialog" import { cn } from "@/lib/utils" import { Post } from "@/types" import { deletePost } from "@/app/server/actions/community" export function Delete({ post, moderationKey = "", onDelete = () => {} }: { post?: Post, moderationKey?: string; onDelete: (post: Post) => void }) { const [isOpen, setOpen] = useState(false) useEffect(() => { if (post?.postId && !isOpen) { setOpen(true) } }, [post?.postId]) const handleDelete = () => { startTransition(() => { const fn = async () => { setOpen(false) if (!post) { return } const postId = post.postId await deletePost({ postId, moderationKey }) onDelete(post) } fn() }) } return ( Delete {post ?
{post.prompt}
: null}
) }