import React, { useState } from 'react'; import { useAuth } from '../../../contexts/AuthContext'; import { useComments, useCreateComment } from '../../../queries/comments'; import { Button } from '../../ui/button'; import { Textarea } from '../../ui/textarea'; import { Card, CardContent } from '../../ui/card'; import { CommentItem } from './CommentItem'; interface CommentSectionProps { articleId?: string; liveBlogId?: string; } export function CommentSection({ articleId, liveBlogId }: CommentSectionProps) { const { isAuthenticated } = useAuth(); const [newComment, setNewComment] = useState(''); const [isSubmitting, setIsSubmitting] = useState(false); const { data: commentsData, isLoading } = useComments({ articleId, liveBlogId, limit: 50, }); const createCommentMutation = useCreateComment(); const comments = commentsData?.data || []; const handleSubmitComment = async (e: React.FormEvent) => { e.preventDefault(); if (!newComment.trim() || !isAuthenticated) return; setIsSubmitting(true); try { await createCommentMutation.mutateAsync({ content: newComment, articleId, liveBlogId, }); setNewComment(''); } catch (error) { console.error('Failed to post comment:', error); } finally { setIsSubmitting(false); } }; return (

Коментари

{isAuthenticated ? (