import { useEffect, useState } from 'react' import { useTranslation } from 'react-i18next' import type { Bookmark } from '@shared/types' import { useBookStore } from '@renderer/stores/useBookStore' import { useEditStore } from '@renderer/stores/useEditStore' import { ipcCall } from '@renderer/lib/ipc-client' interface LandmarkModalProps { open: boolean onClose: () => void } export function LandmarkModal({ open, onClose }: LandmarkModalProps): React.JSX.Element | null { const { t } = useTranslation() const bookId = useBookStore((s) => s.currentBookId) const chapters = useBookStore((s) => s.chapters) const setSelectedChapter = useBookStore((s) => s.setSelectedChapter) const switchTarget = useEditStore((s) => s.switchTarget) const [bookmarks, setBookmarks] = useState([]) useEffect(() => { if (!open || !bookId) return void ipcCall(() => window.electronAPI.bookmark.list(bookId)).then(setBookmarks) }, [open, bookId]) const jumpTo = async (bm: Bookmark): Promise => { setSelectedChapter(bm.chapterId) await switchTarget({ kind: 'chapter', id: bm.chapterId }) onClose() } if (!open) return null return (

{t('landmark.title')}

{bookmarks.map((bm) => { const ch = chapters.find((c) => c.id === bm.chapterId) return (
void jumpTo(bm)} role="button" tabIndex={0} data-testid={`landmark-item-${bm.id}`} >
{bm.landmarkType} · {ch?.title ?? bm.chapterId}
{bm.label}
) })} {bookmarks.length === 0 &&
{t('landmark.empty')}
}
) }