"use client"; import { ChatExportCommentWithUser } from "app-types/chat-export"; import { Avatar, AvatarFallback, AvatarImage } from "ui/avatar"; import { Button } from "ui/button"; import { formatDistanceToNow } from "date-fns"; import { useState } from "react"; import { mutate } from "swr"; import MentionInput from "../mention-input"; import { CornerDownRightIcon } from "lucide-react"; import { notify } from "lib/notify"; export default function Comment({ comment, exportId, depth = 0, maxReplyDepth = Infinity, onReply, }: { comment: ChatExportCommentWithUser; exportId: string; depth?: number; maxReplyDepth?: number; onReply?: () => void; }) { const [isDeleting, setIsDeleting] = useState(false); const handleDelete = async () => { const answer = await notify.confirm({ title: "Delete Comment", description: "Are you sure you want to delete this comment?", }); if (!answer) return; try { setIsDeleting(true); const response = await fetch( `/api/export/${exportId}/comments/${comment.id}`, { method: "DELETE", }, ); if (!response.ok) { throw new Error("Failed to delete comment"); } // Refresh comments mutate(`/api/export/${exportId}/comments`); } catch (error) { console.error("Failed to delete comment:", error); } finally { setIsDeleting(false); } }; return (
{comment.authorName?.[0]?.toUpperCase()}
{comment.authorName} {formatDistanceToNow(new Date(comment.createdAt), { addSuffix: true, })}
{depth < maxReplyDepth && ( )} {comment.isOwner && ( )}
{/* Render replies */} {comment.replies && comment.replies.length > 0 && (
{comment.replies.map((reply) => ( ))}
)}
); }