From 8137c05e53eace57269d51ea6ad7bcb43dd5801d Mon Sep 17 00:00:00 2001 From: vshnosngh Date: Thu, 5 Nov 2026 16:38:59 +0530 Subject: [PATCH] fix(tools): top category slider self-sliding sync, topbar blur removal, web grid filling & mobile section horizontal scroller --- src/components/sections/ToolGridSection.tsx | 201 ++++++++++++++------ src/components/ui/Navbar.tsx | 8 +- 2 files changed, 151 insertions(+), 58 deletions(-) diff --git a/src/components/sections/ToolGridSection.tsx b/src/components/sections/ToolGridSection.tsx index b082b41..206e54a 100644 --- a/src/components/sections/ToolGridSection.tsx +++ b/src/components/sections/ToolGridSection.tsx @@ -1,6 +1,6 @@ 'use client'; -import React, { useState, useMemo, useRef } from 'react'; +import React, { useState, useMemo, useRef, useEffect, useCallback } from 'react'; import Link from 'next/link'; import { Search, @@ -298,6 +298,8 @@ export function ToolGridSection({ const [selectedCategory, setSelectedCategory] = useState('all'); const [searchQuery, setSearchQuery] = useState(''); const railRef = useRef(null); + const buttonRefs = useRef>({}); + const isClickScrollingRef = useRef(false); // Group all tools by category const categorizedTools = useMemo(() => { @@ -335,15 +337,22 @@ export function ToolGridSection({ }); }, [tools, searchQuery, locale]); - // Categories to display based on selectedCategory - const displayedCategories = useMemo(() => { - if (selectedCategory === 'all') { - return categorizedTools; + // Center a pill smoothly in the horizontal top rail + const centerPillInRail = useCallback((catId: string) => { + const pill = buttonRefs.current[catId]; + const rail = railRef.current; + if (pill && rail) { + const pillLeft = pill.offsetLeft; + const pillWidth = pill.offsetWidth; + const railWidth = rail.offsetWidth; + rail.scrollTo({ + left: Math.max(0, pillLeft - railWidth / 2 + pillWidth / 2), + behavior: 'smooth', + }); } - return categorizedTools.filter((group) => group.id === selectedCategory); - }, [categorizedTools, selectedCategory]); + }, []); - // Smooth scroll rail for categories + // Smooth scroll rail for manual chevron arrows const scrollRail = (direction: 'left' | 'right') => { if (railRef.current) { railRef.current.scrollBy({ @@ -353,24 +362,79 @@ export function ToolGridSection({ } }; - // Fluid category tab selection with smooth pill centering - const handleCategoryClick = ( - catId: string, - e?: React.MouseEvent - ) => { + // Fluid click handler: scrolls to category section on page and centers pill in rail + const handleCategoryClick = (catId: string) => { setSelectedCategory(catId); if (searchQuery) setSearchQuery(''); + centerPillInRail(catId); - // Smoothly center the clicked pill in the scrolling rail - if (e?.currentTarget) { - e.currentTarget.scrollIntoView({ - behavior: 'smooth', - inline: 'center', - block: 'nearest', - }); + isClickScrollingRef.current = true; + + if (catId === 'all') { + const el = document.getElementById('tools-catalog'); + if (el) { + const y = el.getBoundingClientRect().top + window.pageYOffset - 90; + window.scrollTo({ top: Math.max(0, y), behavior: 'smooth' }); + } + } else { + const el = document.getElementById(`category-${catId}`); + if (el) { + const headerOffset = 145; // Space for navbar + sticky category rail + const y = el.getBoundingClientRect().top + window.pageYOffset - headerOffset; + window.scrollTo({ top: Math.max(0, y), behavior: 'smooth' }); + } } + + setTimeout(() => { + isClickScrollingRef.current = false; + }, 850); }; + // Synchronized Scroll-Spy: Top slider slides itself as categories slide into view + useEffect(() => { + if (searchQuery) return; + + const handleScroll = () => { + if (isClickScrollingRef.current) return; + + const headerOffset = 180; + const categoryIds = categorizedTools.map((g) => g.id); + + // Check if at the top before the categories start + const catalogEl = document.getElementById('tools-catalog'); + if (catalogEl) { + const catalogTop = catalogEl.getBoundingClientRect().top; + if (catalogTop > 100) { + if (selectedCategory !== 'all') { + setSelectedCategory('all'); + centerPillInRail('all'); + } + return; + } + } + + // Check each category section in chronological order + let matchedCategory = 'all'; + for (const catId of categoryIds) { + const el = document.getElementById(`category-${catId}`); + if (el) { + const rect = el.getBoundingClientRect(); + if (rect.top <= headerOffset + 50 && rect.bottom >= 100) { + matchedCategory = catId; + } + } + } + + if (matchedCategory !== selectedCategory) { + setSelectedCategory(matchedCategory); + centerPillInRail(matchedCategory); + } + }; + + window.addEventListener('scroll', handleScroll, { passive: true }); + return () => window.removeEventListener('scroll', handleScroll); + }, [categorizedTools, searchQuery, selectedCategory, centerPillInRail]); + return (
@@ -390,11 +454,11 @@ export function ToolGridSection({
)} - {/* Sticky Fluid Horizontal Scrolling Category Bar & Search */} + {/* Sticky Solid Category Bar & Search (Immune to topbar blur, solid bg-[#FAF8F5], z-40) */} {(showCategoryFilter || showSearch) && ( -
+
- {/* Category Rail with Fluid Scrolling */} + {/* Category Rail that slides itself smoothly */} {showCategoryFilter && (
{/* Left Scroll Arrow */} @@ -414,7 +478,10 @@ export function ToolGridSection({ > {/* All Categories Pill */}
)} - {/* Content: Categorized Sections or Search Results */} + {/* Content: Search Results or Categorized Sections */} {searchResults ? ( /* Search Results View */
@@ -526,11 +596,26 @@ export function ToolGridSection({
{searchResults.length > 0 ? ( -
- {searchResults.map((tool) => ( - - ))} -
+ <> + {/* Mobile Scroller */} +
+ {searchResults.map((tool) => ( +
+ +
+ ))} +
+ + {/* Web Grid View: Keeps filling naturally */} +
+ {searchResults.map((tool) => ( + + ))} +
+ ) : (

@@ -550,24 +635,11 @@ export function ToolGridSection({ )}

) : ( - /* Categorized Tools Sections (Fluid, All 12 Tools Included) */ + /* Categorized Sections: + - On phones (< sm): Each section has a smooth horizontal scroller + - On web (>= sm): Grid that keeps filling naturally as tools are added */
- {/* Quick reset button if filtered to single category */} - {selectedCategory !== 'all' && ( -
- - - Filtered Category - -
- )} - - {displayedCategories.map((group) => { + {categorizedTools.map((group) => { const theme = CATEGORY_THEMES[group.id]; const catName = group.category ? resolveLocalised(group.category.name, locale) @@ -580,19 +652,19 @@ export function ToolGridSection({
{/* Category Header */} -
+
{theme?.icon || }
-

+

{catName}

- {/* Category Tools Grid with Image-Dominant Cards */} -
+ {/* 1. Phone View (< sm): Horizontal Scroller for this particular section */} +
+
+ {group.tools.map((tool) => ( +
+ +
+ ))} +
+ {/* Swipe hint */} + {group.tools.length > 1 && ( +
+ Swipe to see all {group.tools.length} tools + → +
+ )} +
+ + {/* 2. Web View (>= sm): Grid that keeps filling naturally as tools are added */} +
{group.tools.map((tool) => ( ))} diff --git a/src/components/ui/Navbar.tsx b/src/components/ui/Navbar.tsx index fb7d30f..dfe18bc 100644 --- a/src/components/ui/Navbar.tsx +++ b/src/components/ui/Navbar.tsx @@ -79,16 +79,16 @@ export function Navbar({ config, currentLocale }: NavbarProps) { > {/* 1. Ultra-Smooth High-Performance Gradient Blur Canopy (Active only when menu is closed) */} {!mobileMenuOpen && ( -
+
)}