import React, { useCallback, useEffect, useState } from "react"; import { useNavigate } from "react-router-dom"; import { booksApi } from "../api/books"; import type { EBookListItem } from "../types/book"; import { useAuth } from "../context/AuthContext"; export function LibraryPage() { const [books, setBooks] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const { logout } = useAuth(); const navigate = useNavigate(); const loadBooks = useCallback(async () => { setLoading(true); setError(null); try { const data = await booksApi.getEBooks(); setBooks(data); } catch (err) { setError(err instanceof Error ? err.message : "Failed to load library"); } finally { setLoading(false); } }, []); useEffect(() => { void loadBooks(); }, [loadBooks]); return (

My Library

{error &&

{error}

} {loading && books.length === 0 &&

Loading your library...

} {!loading && !error && books.length === 0 &&

Your library is empty

Add a book to get started

}
{books.map((book) => (
navigate(`/reader/${book.id}`)} style={{ background: "#fff", borderRadius: 12, overflow: "hidden", boxShadow: "0 2px 8px rgba(0,0,0,0.06)", cursor: "pointer" }}>
{book.cover_image ? {book.title} : 📖}

{book.title}

{book.author || "Unknown Author"}

{book.progress !== null &&
}
))}
); }