import clsx from 'clsx'; import React from 'react'; import { useEnv } from '@/context/EnvContext'; import { BookNote } from '@/types/book'; import { useReaderStore } from '@/store/readerStore'; import useScrollToItem from '../../hooks/useScrollToItem'; interface BooknoteItemProps { bookKey: string; item: BookNote; editable?: boolean; } const BooknoteItem: React.FC = ({ bookKey, item, editable = false }) => { const { envConfig } = useEnv(); const { settings, getConfig, saveConfig, getProgress, getView } = useReaderStore(); const { updateBooknotes, setNotebookEditAnnotation, setNotebookVisible } = useReaderStore(); const { text, cfi, note } = item; const progress = getProgress(bookKey); const { isCurrent, viewRef } = useScrollToItem(cfi, progress); const handleClickItem = (event: React.MouseEvent) => { event.preventDefault(); getView(bookKey)?.goTo(cfi); if (note) { setNotebookVisible(true); } }; const deleteNote = (note: BookNote) => { if (!bookKey) return; const config = getConfig(bookKey); if (!config) return; const { booknotes = [] } = config; const updatedNotes = booknotes.filter((item) => item.id !== note.id); const updatedConfig = updateBooknotes(bookKey, updatedNotes); if (updatedConfig) { saveConfig(envConfig, bookKey, updatedConfig, settings); } }; const editNote = (note: BookNote) => { setNotebookEditAnnotation(note); }; return (
  • {item.note && {item.note}}
    {item.note && (
    )}
    {text || ''}
    {editable && (
    e.stopPropagation()} >
    )}
  • ); }; export default BooknoteItem;