diff --git a/frontend/src/core/components/viewer/BookmarkSidebar.tsx b/frontend/src/core/components/viewer/BookmarkSidebar.tsx index 381576edd3..83247f8595 100644 --- a/frontend/src/core/components/viewer/BookmarkSidebar.tsx +++ b/frontend/src/core/components/viewer/BookmarkSidebar.tsx @@ -1,5 +1,5 @@ import { useEffect, useMemo, useState, useCallback } from 'react'; -import { Box, ScrollArea, Group, Text, ActionIcon, Loader, Stack, TextInput, Tooltip } from '@mantine/core'; +import { Box, ScrollArea, Group, Text, ActionIcon, Loader, Stack, TextInput } from '@mantine/core'; import LocalIcon from '@app/components/shared/LocalIcon'; import { useViewer } from '@app/contexts/ViewerContext'; import { PdfBookmarkObject, PdfActionType } from '@embedpdf/models'; @@ -41,7 +41,6 @@ export const BookmarkSidebar = ({ visible, thumbnailVisible, documentCacheKey }: const { getBookmarkState, bookmarkActions, scrollActions, hasBookmarkSupport } = useViewer(); const bookmarkState = getBookmarkState(); const [expanded, setExpanded] = useState>({}); - const [isRefreshing, setIsRefreshing] = useState(false); const [bookmarkCache, setBookmarkCache] = useState>({}); const [errorCache, setErrorCache] = useState>({}); const [searchTerm, setSearchTerm] = useState(''); @@ -75,6 +74,12 @@ export const BookmarkSidebar = ({ visible, thumbnailVisible, documentCacheKey }: } }, [bookmarkActions, documentCacheKey, bookmarkCache, errorCache]); + useEffect(() => { + if (!documentCacheKey) return; + if (!hasBookmarkSupport()) return; + bookmarkActions.fetchBookmarks().catch(() => {}); + }, [documentCacheKey, bookmarkActions, hasBookmarkSupport]); + useEffect(() => { if (!visible) return; if (!hasBookmarkSupport()) return; @@ -85,11 +90,7 @@ export const BookmarkSidebar = ({ visible, thumbnailVisible, documentCacheKey }: if (hasBookmarkEntry || hasErrorEntry) return; if (bookmarkState.isLoading) return; - setIsRefreshing(true); - bookmarkActions - .fetchBookmarks() - .catch(() => {}) - .finally(() => setIsRefreshing(false)); + bookmarkActions.fetchBookmarks().catch(() => {}); }, [ visible, documentCacheKey, @@ -133,22 +134,6 @@ export const BookmarkSidebar = ({ visible, thumbnailVisible, documentCacheKey }: })); }; - const handleRefresh = async () => { - if (!hasBookmarkSupport()) { - setIsRefreshing(false); - return; - } - - setIsRefreshing(true); - try { - await bookmarkActions.fetchBookmarks(); - } catch { - // errors handled via bridge state - } finally { - setIsRefreshing(false); - } - }; - const handleBookmarkClick = (bookmark: PdfBookmarkObject, event: React.MouseEvent) => { const target = bookmark.target; if (target?.type === 'action') { @@ -197,20 +182,6 @@ export const BookmarkSidebar = ({ visible, thumbnailVisible, documentCacheKey }: const filteredBookmarks = useMemo(() => filterBookmarks(bookmarksWithIds), [bookmarksWithIds, filterBookmarks]); - const handleExpandCollapseAll = (expand: boolean) => { - const next: Record = {}; - const setStateRecursively = (nodes: BookmarkNode[], state: boolean) => { - nodes.forEach(node => { - if (node.children && node.children.length > 0) { - next[node.id] = state; - setStateRecursively(node.children as BookmarkNode[], state); - } - }); - }; - setStateRecursively(filteredBookmarks, expand); - setExpanded(next); - }; - const renderBookmarks = (nodes: BookmarkNode[], depth = 0) => { return nodes.map(node => { const hasChildren = Array.isArray(node.children) && node.children.length > 0; @@ -292,45 +263,10 @@ export const BookmarkSidebar = ({ visible, thumbnailVisible, documentCacheKey }: boxShadow: '-2px 0 8px rgba(0, 0, 0, 0.1)', }} > - + Bookmarks - - - handleExpandCollapseAll(false)} - aria-label="Collapse all bookmarks" - > - - - - - handleExpandCollapseAll(true)} - aria-label="Expand all bookmarks" - > - - - - - {bookmarkState.isLoading || isRefreshing ? ( - - ) : ( - - )} - - diff --git a/frontend/src/core/components/viewer/EmbedPdfViewer.tsx b/frontend/src/core/components/viewer/EmbedPdfViewer.tsx index 5c032e8987..32274976f7 100644 --- a/frontend/src/core/components/viewer/EmbedPdfViewer.tsx +++ b/frontend/src/core/components/viewer/EmbedPdfViewer.tsx @@ -35,6 +35,7 @@ const EmbedPdfViewerContent = ({ setActiveFileIndex: externalSetActiveFileIndex, }: EmbedPdfViewerProps) => { const viewerRef = React.useRef(null); + const pdfContainerRef = useRef(null); const [isViewerHovered, setIsViewerHovered] = React.useState(false); const { @@ -309,11 +310,6 @@ const EmbedPdfViewerContent = ({ // Future: Handle signature completion }} /> - )}