import { useState } from "react"; import { useAuth } from "../../context/AuthContext"; import { commentApi } from "../../api/apiService"; const CommentInput = ({ postId, onCommentAdded }) => { const [content, setContent] = useState(""); const [isLoading, setIsLoading] = useState(false); const { user } = useAuth(); const handleContentChange = (e) => { setContent(e.target.value); }; const handleSubmit = async (e) => { e.preventDefault(); if (!content.trim() || !user) return; setIsLoading(true); try { const response = await commentApi.createComment( postId, content, user.username ); setContent(""); if (onCommentAdded) { onCommentAdded(response.data); } } catch (error) { alert("An error occurred while adding the comment."); } finally { setIsLoading(false); } }; return (