"use client"; import { useState, useEffect } from "react"; import Link from "next/link"; import { ArrowRight, ArrowLeft, ChevronRight } from "lucide-react"; import { api } from "@/lib/api"; import { formatDate } from "@/lib/utils"; import { Navbar } from "@/components/public/Navbar"; import { Footer } from "@/components/public/Footer"; interface Post { id: string; slug: string; title: string; excerpt?: string; content?: string; author?: string; authorPubkey?: string; publishedAt?: string; createdAt?: string; categories?: { id: string; name: string; slug: string }[]; featured?: boolean; } interface Category { id: string; name: string; slug: string; } function PostCardSkeleton() { return (
); } function FeaturedPostSkeleton() { return (
); } export default function BlogPage() { const [posts, setPosts] = useState([]); const [categories, setCategories] = useState([]); const [activeCategory, setActiveCategory] = useState("all"); const [page, setPage] = useState(1); const [total, setTotal] = useState(0); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const limit = 9; useEffect(() => { api.getCategories().then(setCategories).catch(() => {}); }, []); useEffect(() => { setLoading(true); setError(null); api .getPosts({ category: activeCategory === "all" ? undefined : activeCategory, page, limit, }) .then(({ posts: data, total: t }) => { setPosts(data); setTotal(t); }) .catch((err) => setError(err.message)) .finally(() => setLoading(false)); }, [activeCategory, page]); const totalPages = Math.ceil(total / limit); const featured = posts.find((p) => p.featured); const regularPosts = featured ? posts.filter((p) => p.id !== featured.id) : posts; return ( <>

From the Nostr Network

Blog

Curated Bitcoin content from the Nostr network

{categories.map((cat) => ( ))}
{error && (
Failed to load posts: {error}
)} {loading ? ( <>
{Array.from({ length: 6 }).map((_, i) => ( ))}
) : posts.length === 0 ? (

No posts yet

Check back soon for curated Bitcoin content.

) : ( <> {featured && page === 1 && (
Featured

{featured.title}

{featured.excerpt && (

{featured.excerpt}

)}
{featured.author && {featured.author}} {featured.publishedAt && ( {formatDate(featured.publishedAt)} )}
)}
{regularPosts.map((post) => ( {post.categories && post.categories.length > 0 && (
{post.categories.map((cat) => ( {cat.name} ))}
)}

{post.title}

{post.excerpt && (

{post.excerpt}

)}
{post.author && {post.author}} {post.author && (post.publishedAt || post.createdAt) && ยท} {(post.publishedAt || post.createdAt) && ( {formatDate(post.publishedAt || post.createdAt!)} )}
Read
))}
{totalPages > 1 && (
Page {page} of {totalPages}
)} )}