From b23bd8e066d0f0ef3a968b7f91c65c1041907bcd Mon Sep 17 00:00:00 2001 From: vshnosngh Date: Thu, 5 Nov 2026 16:46:41 +0530 Subject: [PATCH] feat(tools): replace sticky category bar with in-header floating dock and introduce high-density 2-column mobile gallery --- src/components/sections/ToolGridSection.tsx | 438 +++++++------------- 1 file changed, 151 insertions(+), 287 deletions(-) diff --git a/src/components/sections/ToolGridSection.tsx b/src/components/sections/ToolGridSection.tsx index 206e54a..dc3359d 100644 --- a/src/components/sections/ToolGridSection.tsx +++ b/src/components/sections/ToolGridSection.tsx @@ -1,6 +1,6 @@ 'use client'; -import React, { useState, useMemo, useRef, useEffect, useCallback } from 'react'; +import React, { useState, useMemo, useRef } from 'react'; import Link from 'next/link'; import { Search, @@ -10,8 +10,6 @@ import { Smile, Palette, Sparkles, - ChevronLeft, - ChevronRight, X, Layers, } from 'lucide-react'; @@ -173,7 +171,7 @@ function ToolCardImage({ tool, toolName }: { tool: ToolItem; toolName: string }) if (media.type === 'single') { return ( -
+
{/* eslint-disable-next-line @next/next/no-img-element */} {/* Floating badge */} - + {media.badge} - + Try Tool ↗
@@ -197,7 +195,7 @@ function ToolCardImage({ tool, toolName }: { tool: ToolItem; toolName: string })
{/* Enhanced / After Image (Underneath) */} {/* eslint-disable-next-line @next/next/no-img-element */} @@ -232,29 +230,29 @@ function ToolCardImage({ tool, toolName }: { tool: ToolItem; toolName: string }) style={{ left: `${splitPos}%`, transform: 'translateX(-50%)' }} > {/* Sleek handle pill */} -
+
-
-
+
+
{/* Floating badges */} - + Before - + CRE AI - + Try Tool ↗
); } -// Single Image-Dominant Tool Card Component (~75% Image, Minimal Text) +// Single Image-Dominant Tool Card Component function ToolCard({ tool, locale }: { tool: ToolItem; locale: string }) { const toolName = resolveLocalised(tool.name, locale); const toolSummary = resolveLocalised(tool.summary, locale); @@ -262,23 +260,23 @@ function ToolCard({ tool, locale }: { tool: ToolItem; locale: string }) { return ( - {/* Image Dominant Preview (~75% of visual area) */} + {/* Image Dominant Preview (~85% on phone, ~75% on desktop) */} {/* Minimalist Info Area: Only Title & Subtitle */} -
-
-

+
+
+

{toolName}

-
+
-

+

{toolSummary}

@@ -297,9 +295,6 @@ export function ToolGridSection({ }: ToolGridSectionProps) { 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(() => { @@ -337,252 +332,139 @@ export function ToolGridSection({ }); }, [tools, searchQuery, locale]); - // 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', - }); + // Categories to display based on selectedCategory + const displayedCategories = useMemo(() => { + if (selectedCategory === 'all') { + return categorizedTools; } - }, []); - - // Smooth scroll rail for manual chevron arrows - const scrollRail = (direction: 'left' | 'right') => { - if (railRef.current) { - railRef.current.scrollBy({ - left: direction === 'left' ? -220 : 220, - behavior: 'smooth', - }); - } - }; - - // 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); - - 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 categorizedTools.filter((group) => group.id === selectedCategory); + }, [categorizedTools, selectedCategory]); return ( -
+
{/* Section Heading */} {(title || subtitle) && ( -
+
{title && ( -

+

{resolveLocalised(title, locale)}

)} {subtitle && ( -

+

{resolveLocalised(subtitle, locale)}

)}
)} - {/* Sticky Solid Category Bar & Search (Immune to topbar blur, solid bg-[#FAF8F5], z-40) */} + {/* Elegant Non-Sticky Category Hub & Search (Zero obstruction, no sticky bar under topbar) */} {(showCategoryFilter || showSearch) && ( -
-
- {/* Category Rail that slides itself smoothly */} - {showCategoryFilter && ( -
- {/* Left Scroll Arrow */} +
+ {/* Search Bar - Center Aligned */} + {showSearch && ( +
+ + setSearchQuery(e.target.value)} + className="w-full pl-10 pr-9 py-2.5 rounded-full text-xs sm:text-sm border border-slate-200/90 bg-white text-slate-900 placeholder-slate-400 focus:outline-none focus:border-blue-500 focus:ring-2 focus:ring-blue-500/20 shadow-sm" + /> + {searchQuery && ( + )} +
+ )} - {/* Horizontal Scrollable Categories Container */} -
+
+ {/* All Categories Pill */} + + + {/* Category Pills */} + {categorizedTools.map((group) => { + const isSelected = + selectedCategory === group.id && !searchQuery; + const catName = group.category + ? resolveLocalised(group.category.name, locale) + : group.id; + const theme = CATEGORY_THEMES[group.id]; + + return ( + - - {/* Individual Category Pills */} - {categorizedTools.map((group) => { - const isSelected = - selectedCategory === group.id && !searchQuery; - const catName = group.category - ? resolveLocalised(group.category.name, locale) - : group.id; - const theme = CATEGORY_THEMES[group.id]; - - return ( - - ); - })} -
- - {/* Right Scroll Arrow */} - + {group.tools.length} + + + ); + })}
- )} - - {/* Integrated Search Input */} - {showSearch && ( -
- - setSearchQuery(e.target.value)} - className="w-full pl-10 pr-9 py-2 rounded-full text-xs sm:text-sm border border-slate-200 bg-white text-slate-900 placeholder-slate-400 focus:outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500 shadow-sm" - /> - {searchQuery && ( - - )} -
- )} -
+
+ )}
)} {/* Content: Search Results or Categorized Sections */} {searchResults ? ( /* Search Results View */ -
+
-

+

Found {searchResults.length}{' '} {searchResults.length === 1 ? 'tool' : 'tools'} matching " {searchQuery}" @@ -596,26 +478,12 @@ export function ToolGridSection({

{searchResults.length > 0 ? ( - <> - {/* Mobile Scroller */} -
- {searchResults.map((tool) => ( -
- -
- ))} -
- - {/* Web Grid View: Keeps filling naturally */} -
- {searchResults.map((tool) => ( - - ))} -
- + /* High-Density 2-Col Grid on Phones, Responsive 3-Col Grid on Web */ +
+ {searchResults.map((tool) => ( + + ))} +
) : (

@@ -636,10 +504,25 @@ export function ToolGridSection({

) : ( /* Categorized Sections: - - On phones (< sm): Each section has a smooth horizontal scroller - - On web (>= sm): Grid that keeps filling naturally as tools are added */ -
- {categorizedTools.map((group) => { + - Beautiful 2-Column Visual Gallery on Phones (< sm) + - Rich Responsive Grid that fills naturally on Web (>= sm) */ +
+ {/* Quick reset pill if filtered to single category */} + {selectedCategory !== 'all' && ( +
+ + + Filtered Category + +
+ )} + + {displayedCategories.map((group) => { const theme = CATEGORY_THEMES[group.id]; const catName = group.category ? resolveLocalised(group.category.name, locale) @@ -652,23 +535,23 @@ export function ToolGridSection({
{/* Category Header */} -
-
+
+
- {theme?.icon || } + {theme?.icon || }
-
-

+
+

{catName}

{catDesc && ( -

+

{catDesc}

)} @@ -686,29 +569,10 @@ export function ToolGridSection({

- {/* 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 */} -
+ {/* Responsive Visual Grid: + - 2-Column High-Density Visual Gallery on Phones (< sm) + - 3-Column Responsive Grid on Web/Desktop (>= sm) that continuously fills as tools are added */} +
{group.tools.map((tool) => ( ))}