import { useCallback, useEffect, useState } from "react"; import { PostList } from "../components/PostList"; function getPosts(data) { return Array.isArray(data) ? data : data.posts || data.items || []; } export function FeedPage({ loadPosts, editPost, deletePost, loadImage, currentUserId, currentUsername }) { const [posts, setPosts] = useState([]); const [error, setError] = useState(""); const [loading, setLoading] = useState(true); const refresh = useCallback(() => { setError(""); setLoading(true); return loadPosts() .then((data) => { const rawPosts = getPosts(data); // Filter out logged-in user's own posts on feed const otherUserPosts = rawPosts.filter((post) => { const authorId = post.author_id ?? post.authorId ?? post.author?.id; if (authorId !== undefined && authorId !== null) { return String(authorId) !== String(currentUserId); } if (post.author_username && currentUsername) { return post.author_username !== currentUsername; } return true; }); setPosts(otherUserPosts); }) .catch((loadError) => setError(loadError.message)) .finally(() => setLoading(false)); }, [loadPosts, currentUserId, currentUsername]); useEffect(() => { refresh(); }, [refresh]); async function handleEdit(id, data) { await editPost(id, data); await refresh(); } async function handleDelete(id) { await deletePost(id); await refresh(); } return (

Your daily archive

Community Feed

Explore posts from others
{error ?

{error}

: null} {loading ? (

Loading community feed...

) : posts.length === 0 ? (

No posts from other users yet

Posts created by you will appear on your profile. Check back later for community updates!

) : ( )}
); }