fix: hide highlights button when scrolled to the top

- Highlights button now hidden when at the very top of the page
- Tracks scroll position and hides button when scrollY <= 10px
- Bookmark button remains visible as always
- Highlights button appears when scrolling up from below
- Improves UX by reducing visual clutter at page top
This commit is contained in:
Gigi
2025-10-15 12:17:44 +02:00
parent bc4c96ee35
commit 4f03a2c276

View File

@@ -1,4 +1,4 @@
import React, { useEffect, useRef } from 'react' import React, { useEffect, useRef, useState } from 'react'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { faBookmark, faHighlighter } from '@fortawesome/free-solid-svg-icons' import { faBookmark, faHighlighter } from '@fortawesome/free-solid-svg-icons'
import { RelayPool } from 'applesauce-relay' import { RelayPool } from 'applesauce-relay'
@@ -105,14 +105,30 @@ const ThreePaneLayout: React.FC<ThreePaneLayoutProps> = (props) => {
const highlightsRef = useRef<HTMLDivElement>(null) const highlightsRef = useRef<HTMLDivElement>(null)
const mainPaneRef = useRef<HTMLDivElement>(null) const mainPaneRef = useRef<HTMLDivElement>(null)
// Detect scroll direction to hide/show mobile buttons // Detect scroll direction and position to hide/show mobile buttons
// Only hide on scroll down when viewing article content // Only hide on scroll down when viewing article content
const isViewingArticle = !!(props.selectedUrl) const isViewingArticle = !!(props.selectedUrl)
const scrollDirection = useScrollDirection({ const scrollDirection = useScrollDirection({
threshold: 10, threshold: 10,
enabled: isMobile && !props.isSidebarOpen && props.isHighlightsCollapsed && isViewingArticle enabled: isMobile && !props.isSidebarOpen && props.isHighlightsCollapsed && isViewingArticle
}) })
const showMobileButtons = scrollDirection !== 'down'
// Track if we're at the top of the page
const [isAtTop, setIsAtTop] = useState(true)
useEffect(() => {
if (!isMobile || !isViewingArticle) return
const handleScroll = () => {
setIsAtTop(window.scrollY <= 10)
}
handleScroll() // Check initial position
window.addEventListener('scroll', handleScroll, { passive: true })
return () => window.removeEventListener('scroll', handleScroll)
}, [isMobile, isViewingArticle])
const showMobileButtons = scrollDirection !== 'down' && !isAtTop
// Lock body scroll when mobile sidebar or highlights is open // Lock body scroll when mobile sidebar or highlights is open
useEffect(() => { useEffect(() => {