import { useEffect, useState } from "react"; import { useTranslation } from "react-i18n-lite"; import styles from "./FinishedBooksShelf.module.css"; export interface ShelfBook { id: number; title: string; author: string; cover_image: string | null; format: string; genre: string; } interface FinishedBooksShelfProps { books: ShelfBook[]; defaultExpanded?: boolean; onOpenBook: (book: ShelfBook) => void; onContextMenu: (e: React.MouseEvent, book: ShelfBook) => void; } export function FinishedBooksShelf({ books, defaultExpanded = false, onOpenBook, onContextMenu, }: FinishedBooksShelfProps) { const { t } = useTranslation(); const [expanded, setExpanded] = useState(defaultExpanded); useEffect(() => { if (defaultExpanded) setExpanded(true); }, [defaultExpanded]); if (books.length === 0) return null; return (
{expanded && (
{books.map((book) => (
onOpenBook(book)} onKeyDown={(e) => { if (e.key === "Enter" || e.key === " ") { e.preventDefault(); onOpenBook(book); } }} onContextMenu={(e) => onContextMenu(e, book)} >
{book.cover_image ? ( ) : ( 📖 )} {t("library.readingStatus.finished")}

{book.title}

{book.author}

))}
)}
); }