"use client" import { useState, useEffect } from "react" import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card" interface LibraryNote { id: string date: string title: string content: string } export function LibraryNotesContent() { const [notes, setNotes] = useState([]) const [error, setError] = useState(null) useEffect(() => { fetch("/api/library-notes") .then((response) => { if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`) } return response.json() }) .then((data) => { if (!data.notes || !Array.isArray(data.notes)) { throw new Error("Invalid data structure") } setNotes(data.notes.sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime())) }) .catch((error) => { console.error("Error loading library notes data:", error) setError(`Failed to load library notes data: ${error.message}`) }) }, []) if (error) { return
{error}
} if (notes.length === 0) { return
Loading library notes data...
} return (
{notes.map((note) => ( {note.title}

{new Date(note.date).toLocaleDateString()}

{note.content}

))}
) }