feat: scroll to highlight in article when clicking highlight item

- Add onHighlightClick callback to HighlightItem
- Make entire highlight item clickable with pointer cursor
- Reuse existing setSelectedHighlightId to trigger scroll
- Clicking a highlight in sidebar scrolls to it in article view
- Works with existing click-to-scroll from article to sidebar

Users can now click highlights in either direction:
- Click highlight in article → scrolls to item in sidebar
- Click highlight in sidebar → scrolls to text in article
This commit is contained in:
Gigi
2025-10-05 02:03:28 +01:00
parent 6ae101c9c6
commit d9b50f80d0
3 changed files with 21 additions and 3 deletions

View File

@@ -141,6 +141,7 @@ const Bookmarks: React.FC<BookmarksProps> = ({ relayPool, onLogout }) => {
onToggleUnderlines={setShowUnderlines}
selectedHighlightId={selectedHighlightId}
onRefresh={handleFetchHighlights}
onHighlightClick={setSelectedHighlightId}
/>
</div>
</div>

View File

@@ -8,9 +8,10 @@ interface HighlightItemProps {
highlight: Highlight
onSelectUrl?: (url: string) => void
isSelected?: boolean
onHighlightClick?: (highlightId: string) => void
}
export const HighlightItem: React.FC<HighlightItemProps> = ({ highlight, onSelectUrl, isSelected }) => {
export const HighlightItem: React.FC<HighlightItemProps> = ({ highlight, onSelectUrl, isSelected, onHighlightClick }) => {
const itemRef = useRef<HTMLDivElement>(null)
useEffect(() => {
@@ -18,6 +19,13 @@ export const HighlightItem: React.FC<HighlightItemProps> = ({ highlight, onSelec
itemRef.current.scrollIntoView({ behavior: 'smooth', block: 'center' })
}
}, [isSelected])
const handleItemClick = () => {
if (onHighlightClick) {
onHighlightClick(highlight.id)
}
}
const handleLinkClick = (url: string, e: React.MouseEvent) => {
if (onSelectUrl) {
e.preventDefault()
@@ -35,7 +43,13 @@ export const HighlightItem: React.FC<HighlightItemProps> = ({ highlight, onSelec
const sourceLink = getSourceLink()
return (
<div ref={itemRef} className={`highlight-item ${isSelected ? 'selected' : ''}`} data-highlight-id={highlight.id}>
<div
ref={itemRef}
className={`highlight-item ${isSelected ? 'selected' : ''}`}
data-highlight-id={highlight.id}
onClick={handleItemClick}
style={{ cursor: onHighlightClick ? 'pointer' : 'default' }}
>
<div className="highlight-quote-icon">
<FontAwesomeIcon icon={faQuoteLeft} />
</div>

View File

@@ -14,6 +14,7 @@ interface HighlightsPanelProps {
onToggleUnderlines?: (show: boolean) => void
selectedHighlightId?: string
onRefresh?: () => void
onHighlightClick?: (highlightId: string) => void
}
export const HighlightsPanel: React.FC<HighlightsPanelProps> = ({
@@ -25,7 +26,8 @@ export const HighlightsPanel: React.FC<HighlightsPanelProps> = ({
selectedUrl,
onToggleUnderlines,
selectedHighlightId,
onRefresh
onRefresh,
onHighlightClick
}) => {
const [showUnderlines, setShowUnderlines] = useState(true)
@@ -140,6 +142,7 @@ export const HighlightsPanel: React.FC<HighlightsPanelProps> = ({
highlight={highlight}
onSelectUrl={onSelectUrl}
isSelected={highlight.id === selectedHighlightId}
onHighlightClick={onHighlightClick}
/>
))}
</div>