From daab93c9f3430f9d4ea0c1bec50eb24fb12a9751 Mon Sep 17 00:00:00 2001 From: bender Date: Sat, 21 Mar 2026 22:30:37 +0000 Subject: [PATCH] Update src/app/page.tsx --- src/app/page.tsx | 72 +++++++++++++++++++++++++++++++----------------- 1 file changed, 46 insertions(+), 26 deletions(-) diff --git a/src/app/page.tsx b/src/app/page.tsx index 18f15da..263c2a2 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -16,35 +16,52 @@ export default function LandingPage() { const [showModal, setShowModal] = useState(false); const [showBackToTop, setShowBackToTop] = useState(false); const [showViewMoreButton, setShowViewMoreButton] = useState(false); + const [scrollDirection, setScrollDirection] = useState<'up' | 'down'>('down'); + const [lastScrollY, setLastScrollY] = useState(0); const viewMoreButtonRef = useRef(null); + const sixthItemRef = useRef(null); useEffect(() => { + let ticking = false; + const handleScroll = () => { - setShowBackToTop(window.scrollY > 300); + if (!ticking) { + window.requestAnimationFrame(() => { + const currentScrollY = window.scrollY; + setShowBackToTop(currentScrollY > 300); + + // Determine scroll direction + if (currentScrollY > lastScrollY) { + setScrollDirection('down'); + } else { + setScrollDirection('up'); + } + setLastScrollY(currentScrollY); + + // Check if 6th item is in view + if (sixthItemRef.current) { + const rect = sixthItemRef.current.getBoundingClientRect(); + const isInView = rect.top < window.innerHeight && rect.bottom > 0; + const isScrollingDown = scrollDirection === 'down'; + + // Show button when 6th item is reached AND scrolling down + // Hide button when scrolling back up past the 6th item + if (isInView && isScrollingDown) { + setShowViewMoreButton(true); + } else if (!isInView && scrollDirection === 'up') { + setShowViewMoreButton(false); + } + } + + ticking = false; + }); + ticking = true; + } }; window.addEventListener('scroll', handleScroll); return () => window.removeEventListener('scroll', handleScroll); - }, []); - - useEffect(() => { - const observer = new IntersectionObserver( - ([entry]) => { - setShowViewMoreButton(entry.isIntersecting); - }, - { threshold: 0.1 } - ); - - if (viewMoreButtonRef.current) { - observer.observe(viewMoreButtonRef.current); - } - - return () => { - if (viewMoreButtonRef.current) { - observer.unobserve(viewMoreButtonRef.current); - } - }; - }, []); + }, [lastScrollY, scrollDirection]); const scrollToGallery = () => { const gallerySectionElement = document.getElementById('gallery'); @@ -419,16 +436,19 @@ export default function LandingPage() { products={initialDresses} /> - {/* View More Button - Positioned after 6th picture, visible when 6th item is in view */} -
- {showViewMoreButton && ( + {/* Reference to 6th item for scroll detection */} +
+ + {/* More Button - Positioned after 6th picture, visible when 6th item is reached and scrolling down */} +
+ {showViewMoreButton && scrollDirection === 'down' && (
@@ -660,4 +680,4 @@ export default function LandingPage() {
); -} +} \ No newline at end of file -- 2.49.1