import React, { useState } from 'react'; import { api } from '../services/api'; import { useUsername } from '../context/UsernameContext'; const CreateCommentModal = ({ isOpen, postId, onClose, onCommentCreated }) => { const [content, setContent] = useState(''); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const { username } = useUsername(); const handleSubmit = async (e) => { e.preventDefault(); if (!content.trim()) return; setLoading(true); setError(null); try { const newComment = await api.createComment(postId, username, content.trim()); onCommentCreated(newComment); setContent(''); onClose(); } catch (err) { setError(err.message); } finally { setLoading(false); } }; if (!isOpen) return null; return (

Add Comment

{error && (
{error}
)}