mirror of
https://github.com/dergigi/boris.git
synced 2026-02-11 18:14:31 +01:00
fix: scroll to highlight in article when clicking sidebar item
- Add selectedHighlightId prop to ContentPanel - Add useEffect to watch for selectedHighlightId changes - Find and scroll to the corresponding mark element - Temporarily brighten the highlight for visual feedback - Pass selectedHighlightId from Bookmarks to ContentPanel Now clicking a highlight in the sidebar properly scrolls to and highlights the text in the article view.
This commit is contained in:
@@ -128,6 +128,7 @@ const Bookmarks: React.FC<BookmarksProps> = ({ relayPool, onLogout }) => {
|
||||
highlights={highlights}
|
||||
showUnderlines={showUnderlines}
|
||||
onHighlightClick={setSelectedHighlightId}
|
||||
selectedHighlightId={selectedHighlightId}
|
||||
/>
|
||||
</div>
|
||||
<div className="pane highlights">
|
||||
|
||||
@@ -15,6 +15,7 @@ interface ContentPanelProps {
|
||||
highlights?: Highlight[]
|
||||
showUnderlines?: boolean
|
||||
onHighlightClick?: (highlightId: string) => void
|
||||
selectedHighlightId?: string
|
||||
}
|
||||
|
||||
const ContentPanel: React.FC<ContentPanelProps> = ({
|
||||
@@ -25,10 +26,36 @@ const ContentPanel: React.FC<ContentPanelProps> = ({
|
||||
selectedUrl,
|
||||
highlights = [],
|
||||
showUnderlines = true,
|
||||
onHighlightClick
|
||||
onHighlightClick,
|
||||
selectedHighlightId
|
||||
}) => {
|
||||
const contentRef = useRef<HTMLDivElement>(null)
|
||||
|
||||
// Scroll to selected highlight in article when clicked from sidebar
|
||||
useEffect(() => {
|
||||
if (!selectedHighlightId || !contentRef.current) {
|
||||
return
|
||||
}
|
||||
|
||||
// Find the mark element with the matching highlight ID
|
||||
const markElement = contentRef.current.querySelector(`mark.content-highlight[data-highlight-id="${selectedHighlightId}"]`)
|
||||
|
||||
if (markElement) {
|
||||
console.log('📍 Scrolling to highlight in article:', selectedHighlightId.slice(0, 8))
|
||||
markElement.scrollIntoView({ behavior: 'smooth', block: 'center' })
|
||||
|
||||
// Temporarily enhance the highlight to show it's selected
|
||||
const originalBackground = (markElement as HTMLElement).style.background
|
||||
;(markElement as HTMLElement).style.background = 'rgba(255, 255, 0, 0.7)'
|
||||
|
||||
setTimeout(() => {
|
||||
(markElement as HTMLElement).style.background = originalBackground
|
||||
}, 1500)
|
||||
} else {
|
||||
console.log('⚠️ Could not find mark element for highlight:', selectedHighlightId.slice(0, 8))
|
||||
}
|
||||
}, [selectedHighlightId])
|
||||
|
||||
// Filter highlights relevant to the current URL
|
||||
const relevantHighlights = useMemo(() => {
|
||||
if (!selectedUrl || highlights.length === 0) {
|
||||
|
||||
Reference in New Issue
Block a user