"use client"; import { useState, useEffect } from "react"; import { useRouter } from "next/navigation"; import { Button } from "@/components/ui/button"; import { Plus, Loader2 } from "lucide-react"; import { Navbar } from "@/components/landing/navbar"; interface Story { id: string; title: string; slug: string; createdAt: string; pageCount: number; coverImage: string | null; } export default function StoriesPage() { const router = useRouter(); const [stories, setStories] = useState([]); const [isLoading, setIsLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { fetchStories(); }, []); const fetchStories = async () => { try { const response = await fetch("/api/stories"); if (!response.ok) { throw new Error("Failed to fetch stories"); } const data = await response.json(); setStories(data.stories); } catch (err) { setError(err instanceof Error ? err.message : "Failed to load stories"); } finally { setIsLoading(false); } }; if (isLoading) { return (

Loading your comic library...

); } if (error) { return (

{error}

); } return (
{stories.length === 0 ? (

No comics yet

Create your first comic story to build your library!

) : (
{stories.map((story) => ( ))}
)}
); }