import React, { useState } from "react"; import { useAnnotations } from "@/context/AnnotationsContext"; import type { Note } from "@/types"; interface NoteListProps { bookId?: string; onNavigateToPage?: (bookId: string, page: number) => void; } export function NoteList({ bookId, onNavigateToPage, }: NoteListProps): React.ReactElement { const { state, loadNotes, editNote, removeNote } = useAnnotations(); const [editingId, setEditingId] = useState(null); const [editContent, setEditContent] = useState(""); const [deletingId, setDeletingId] = useState(null); const [savingId, setSavingId] = useState(null); React.useEffect(() => { loadNotes(bookId); }, [loadNotes, bookId]); const handleEdit = (note: Note): void => { setEditingId(note.id); setEditContent(note.content); }; const handleSave = async (id: string): Promise => { setSavingId(id); try { await editNote(id, editContent.trim()); setEditingId(null); } catch { // error handled by context } finally { setSavingId(null); } }; const handleCancelEdit = (): void => { setEditingId(null); setEditContent(""); }; const handleDelete = async (id: string): Promise => { setDeletingId(id); try { await removeNote(id); } catch { // error handled by context } finally { setDeletingId(null); } }; if (state.notesLoading) { return
Loading notes...
; } if (state.notes.length === 0) { return (
No notes yet. Select a passage and add a note while reading.
); } return (
{state.notes.map((note: Note) => (
Note Page {note.page} {new Date(note.created_at).toLocaleDateString()}
{note.location_text && (
“{note.location_text}”
)}
{editingId === note.id ? (