import DeleteModal from '@/components/inertia/delete-modal'; import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar'; import { Button } from '@/components/ui/button'; import { Card, CardContent, CardHeader } from '@/components/ui/card'; import { Textarea } from '@/components/ui/textarea'; import { cn } from '@/lib/utils'; import { useForm, usePage } from '@inertiajs/react'; import { MessageCircle, Send, Trash2 } from 'lucide-react'; import { BlogShowProps } from '../show'; const BlogComments = () => { const { props } = usePage(); const { auth, blog, translate } = props; const { button, frontend, input } = translate; // Comment form const { data: commentData, setData: setCommentData, post: postComment, processing: commentProcessing, reset: resetComment, } = useForm({ content: '', blog_id: blog.id, }); // Reply form const { data: replyData, setData: setReplyData, post: postReply, processing: replyProcessing, reset: resetReply, } = useForm({ content: '', blog_id: blog.id, parent_id: null as number | string | null, }); const handleSubmitComment = (e: React.FormEvent) => { e.preventDefault(); if (!commentData.content.trim()) return; postComment(route('blogs.comments.store'), { preserveScroll: true, onSuccess: () => { resetComment(); }, }); }; const handleSubmitReply = (e: React.FormEvent) => { e.preventDefault(); if (!replyData.content.trim()) return; postReply(route('blogs.comments.store'), { preserveScroll: true, onSuccess: () => { resetReply(); }, }); }; // Format date const formatDate = (dateString: string) => { return new Date(dateString).toLocaleDateString('en-US', { year: 'numeric', month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit', }); }; // Get user initials const getUserInitials = (name: string) => { return name .split(' ') .map((n) => n.charAt(0)) .join('') .toUpperCase() .slice(0, 2); }; return (
{/* Comment Form */}

{frontend.post_a_comment}