"use client" import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table" import { BookNoteModal } from "./book-note-modal" import { useState, useEffect } from "react" import { fetchBookNotes } from "@/lib/fetchBookNotes" interface BookNote { id: string title: string author: string year: number coverImage: string goodreadsLink: string grammar: { part1: string part2: string } logic: string rhetoric: string review: string } export function NotesSection() { const [notes, setNotes] = useState([]) const [selectedBook, setSelectedBook] = useState(null) const [isLoading, setIsLoading] = useState(true) const [error, setError] = useState(null) useEffect(() => { async function loadNotes() { try { const fetchedNotes = await fetchBookNotes() setNotes(fetchedNotes) } catch (err) { setError("Failed to load notes. Please try again later.") } finally { setIsLoading(false) } } loadNotes() }, []) if (isLoading) { return

Loading notes...

} if (error) { return

{error}

} if (notes.length === 0) { return

No notes available.

} return (
Title Author Year {notes.map((book) => ( setSelectedBook(book)}> {book.title} {book.author} {book.year} ))}
{selectedBook && ( setSelectedBook(null)} /> )}
) }