import { useEffect, useState } from 'react'; import { useParams } from 'react-router-dom'; const API_BASE = 'http://localhost:8000'; const PostDetails = () => { const { postId } = useParams(); const [post, setPost] = useState(null); const [comments, setComments] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(''); useEffect(() => { const fetchDetails = async () => { setLoading(true); setError(''); try { const postRes = await fetch(`${API_BASE}/posts/${postId}`); if (!postRes.ok) throw new Error('Post not found'); const postData = await postRes.json(); setPost(postData); const commentsRes = await fetch(`${API_BASE}/posts/${postId}/comments`); if (!commentsRes.ok) throw new Error('Comments not found'); const commentsData = await commentsRes.json(); setComments(commentsData); } catch { setError('Failed to load post or comments.'); } finally { setLoading(false); } }; fetchDetails(); }, [postId]); if (loading) { return