"use client"; import { useState, useEffect } from "react"; import { Container } from "@/components/layout/Container"; import { PostCard } from "@/components/post/PostCard"; import { PostCardSkeleton } from "@/components/post/PostCardSkeleton"; import { Button } from "@/components/ui/Button"; import { api } from "@/lib/api"; import type { Post } from "@/types/api"; export default function HomePage() { const [posts, setPosts] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const [page, setPage] = useState(1); const [total, setTotal] = useState(0); const limit = 10; useEffect(() => { async function fetchPosts() { setLoading(true); setError(null); try { const response = await api.getPosts(page, limit); setPosts(response.posts ?? []); setTotal(response.total ?? 0); } catch { setError("Could not retrieve latest transmission."); } finally { setLoading(false); } } fetchPosts(); }, [page]); const totalPages = Math.ceil(total / limit); return (

Latest

{error && (

{error}

)} {loading && ( <> )} {!loading && !error && posts?.length === 0 && (

No posts yet.

)} {!loading && !error && posts?.map((post) => ( ))} {!loading && totalPages > 1 && (
{page} / {totalPages}
)}
); }