import React from "react"; import { useAnnotations } from "@/context/AnnotationsContext"; import type { AnnotationEntry } from "@/types"; interface AnnotationsDashboardProps { bookId?: string; onNavigateToPage?: (bookId: string, page: number) => void; } export function AnnotationsDashboard({ bookId, onNavigateToPage, }: AnnotationsDashboardProps): React.ReactElement { const { mergedAnnotations, loadBookmarks, loadNotes, removeBookmark, removeNote, state, } = useAnnotations(); React.useEffect(() => { loadBookmarks(bookId); loadNotes(bookId); }, [loadBookmarks, loadNotes, bookId]); const handleDelete = async (entry: AnnotationEntry): Promise => { if (entry.kind === "bookmark") { await removeBookmark(entry.id); } else { await removeNote(entry.id); } }; if (state.bookmarksLoading || state.notesLoading) { return
Loading annotations...
; } if (mergedAnnotations.length === 0) { return (
No bookmarks or notes yet.
); } return (
{state.bookmarks.length} bookmarks · {state.notes.length} notes
{mergedAnnotations.map((entry: AnnotationEntry) => (
{entry.kind === "bookmark" ? "Bookmark" : "Note"} {entry.book_title} p.{entry.page} {new Date(entry.created_at).toLocaleDateString()}
{entry.location_text && (
“{entry.location_text}”
)} {entry.kind === "note" && entry.content && (

{entry.content}

)}
{onNavigateToPage && ( )}
))}
); }