"use client"; import { motion } from "framer-motion"; import { BookOpen } from "lucide-react"; import { useEffect, useState } from "react"; import { useTranslations } from "next-intl"; interface CurrentlyReading { title: string; authors: string[]; image: string | null; progress: number; startedAt: string | null; } const CurrentlyReading = () => { const t = useTranslations("home.about.currentlyReading"); const [books, setBooks] = useState([]); const [loading, setLoading] = useState(true); useEffect(() => { // Nur einmal beim Laden der Seite const fetchCurrentlyReading = async () => { try { const res = await fetch("/api/n8n/hardcover/currently-reading", { cache: "default", }); if (!res.ok) { throw new Error("Failed to fetch"); } const data = await res.json(); // Handle both single book and array of books if (data.currentlyReading) { const booksArray = Array.isArray(data.currentlyReading) ? data.currentlyReading : [data.currentlyReading]; setBooks(booksArray); } else { setBooks([]); } } catch (error) { if (process.env.NODE_ENV === "development") { console.error("Error fetching currently reading:", error); } setBooks([]); } finally { setLoading(false); } }; fetchCurrentlyReading(); }, []); // Leeres Array = nur einmal beim Mount // Zeige nichts wenn kein Buch gelesen wird oder noch geladen wird if (loading || books.length === 0) { return null; } return (
{/* Header */}

{t("title")} {books.length > 1 && `(${books.length})`}

{/* Books List */} {books.map((book, index) => ( {/* Background Blob Animation */}
{/* Book Cover */} {book.image && (
{book.title} {/* Glossy Overlay */}
)} {/* Book Info */}
{/* Title */}

{book.title}

{/* Authors */}

{book.authors.join(", ")}

{/* Progress Bar */}
{t("progress")} {book.progress}%
))}
); }; export default CurrentlyReading;