import { useEffect, useState } from 'react' import { api } from '../lib/api.js' export default function Feed() { const [posts, setPosts] = useState([]) const [openId, setOpenId] = useState(null) const [comments, setComments] = useState([]) const [draft, setDraft] = useState('') const [error, setError] = useState(null) const load = () => api.get('/posts/feed').then(setPosts).catch(e => setError(e.message)) useEffect(() => { load() }, []) const open = async (id) => { setOpenId(id) setComments(await api.get(`/posts/${id}/comments`)) } const send = async () => { if (!draft.trim()) return try { await api.post(`/posts/${openId}/comments`, { description: draft }) setDraft('') setComments(await api.get(`/posts/${openId}/comments`)) load() } catch (e) { setError(e.message) } } return (
Nothing published yet.
} {posts.map(p => (