import clsx from 'clsx'; import dayjs from 'dayjs'; import React, { useMemo } from 'react'; import { BookNote } from '@/types/book'; import { useEnv } from '@/context/EnvContext'; import { useBookDataStore } from '@/store/bookDataStore'; import { useReaderStore } from '@/store/readerStore'; import { useSidebarStore } from '@/store/sidebarStore'; import { useResponsiveSize } from '@/hooks/useResponsiveSize'; interface AnnotationNotesProps { bookKey: string; isVertical: boolean; notes: BookNote[]; toolsVisible: boolean; triangleDir: 'up' | 'down' | 'left' | 'right'; popupWidth: number; popupHeight: number; onDismiss: () => void; } const AnnotationNotes: React.FC = ({ bookKey, isVertical, notes, toolsVisible, triangleDir, popupWidth, popupHeight, onDismiss, }) => { const { appService } = useEnv(); const { getConfig, setConfig } = useBookDataStore(); const { setHoveredBookKey } = useReaderStore(); const { setSideBarVisible } = useSidebarStore(); const config = getConfig(bookKey); const maxSize = useResponsiveSize(250); const sortedNotes = useMemo(() => { return [...notes].sort((a, b) => b.updatedAt - a.updatedAt); }, [notes]); const handleShowAnnotation = (note: BookNote) => { if (!note.id) return; if (appService?.isMobile) { onDismiss(); } setHoveredBookKey(''); setSideBarVisible(true); if (config?.viewSettings) { setConfig(bookKey, { viewSettings: { ...config.viewSettings, sideBarTab: 'annotations' }, }); } }; return (
{sortedNotes.map((note, index) => (
handleShowAnnotation?.(note)} className={clsx( 'popup-container cursor-pointer rounded-lg bg-gray-600 shadow-lg transition-colors', )} style={ isVertical ? { minWidth: 'max-content', height: `${popupHeight}px`, maxHeight: `${popupHeight}px`, } : {} } > {note.note && (
{note.note} {dayjs(note.createdAt).fromNow()}
)}
))}
); }; export default AnnotationNotes;