import { useState } from "react"; import Modal from "./Modal"; import { postApi } from "../../api/apiService"; import { useAuth } from "../../context/AuthContext"; const PostingModal = ({ isOpen, onClose, onPostCreated }) => { const [content, setContent] = useState(""); const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(""); const { user } = useAuth(); const handleContentChange = (e) => { setContent(e.target.value); if (error) setError(""); }; const handleSubmit = async () => { if (!content.trim()) { setError("Please enter content."); return; } setIsLoading(true); setError(""); try { const response = await postApi.createPost(content, user.username); setContent(""); onClose(); if (onPostCreated) { onPostCreated(response.data); } } catch (error) { setError("An error occurred while creating the post. Please try again."); } finally { setIsLoading(false); } }; const handleCancel = () => { if ( content.trim() && !window.confirm("You have unsaved content. Are you sure you want to cancel?") ) { return; } setContent(""); onClose(); }; return (