feat(tools): complete 12-tool suite across all categories and fluid category listing navigation
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
'use client';
|
||||
|
||||
import React, { useState, useMemo, useRef, useEffect } from 'react';
|
||||
import React, { useState, useMemo, useRef } from 'react';
|
||||
import Link from 'next/link';
|
||||
import {
|
||||
Search,
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
ChevronLeft,
|
||||
ChevronRight,
|
||||
X,
|
||||
Layers,
|
||||
} from 'lucide-react';
|
||||
import { ToolItem, CategoryItem, AppItem, resolveLocalised } from '@/types';
|
||||
|
||||
@@ -33,62 +34,75 @@ type ToolMediaConfig =
|
||||
| { type: 'comparison'; before: string; after: string }
|
||||
| { type: 'single'; image: string; badge: string };
|
||||
|
||||
// Media resolver for tool cards
|
||||
// Comprehensive media resolver for all tools
|
||||
function getToolMedia(tool: ToolItem): ToolMediaConfig {
|
||||
const example = tool.content?.examples?.[0];
|
||||
|
||||
// Specific bespoke high-res local media
|
||||
if (tool.slug === 'background-remover') {
|
||||
return {
|
||||
type: 'single',
|
||||
image: '/management/pages/home/sections/our-tools/background-remover/poster.jpg',
|
||||
badge: 'Alpha Matting',
|
||||
};
|
||||
}
|
||||
|
||||
if (tool.slug === 'polaroid-maker') {
|
||||
return {
|
||||
type: 'single',
|
||||
image: '/management/pages/home/sections/our-tools/polaroid-maker/image.jpg',
|
||||
badge: 'Vintage Polaroid',
|
||||
};
|
||||
}
|
||||
|
||||
const localDefaults: Record<string, { before: string; after: string }> = {
|
||||
const localDefaults: Record<string, ToolMediaConfig> = {
|
||||
'blemish-remover': {
|
||||
type: 'comparison',
|
||||
before: '/management/pages/home/sections/our-tools/blemish-remover/before.jpg',
|
||||
after: '/management/pages/home/sections/our-tools/blemish-remover/after.jpg',
|
||||
},
|
||||
'teeth-whitener': {
|
||||
type: 'comparison',
|
||||
before: '/management/pages/home/sections/our-tools/teeth-whitener/before.jpg',
|
||||
after: '/management/pages/home/sections/our-tools/teeth-whitener/after.jpg',
|
||||
},
|
||||
'eye-redness-remover': {
|
||||
type: 'comparison',
|
||||
before: '/management/pages/home/sections/our-tools/eye-redness-remover/before.jpg',
|
||||
after: '/management/pages/home/sections/our-tools/eye-redness-remover/after.jpg',
|
||||
},
|
||||
'eye-bag-remover': {
|
||||
type: 'comparison',
|
||||
before: '/management/pages/home/sections/our-tools/eye-bag-remover/before.jpg',
|
||||
after: '/management/pages/home/sections/our-tools/eye-bag-remover/after.jpg',
|
||||
},
|
||||
'portrait-glow': {
|
||||
type: 'comparison',
|
||||
before: '/management/pages/home/sections/our-tools/portrait-glow/before.jpg',
|
||||
after: '/management/pages/home/sections/our-tools/portrait-glow/after.jpg',
|
||||
},
|
||||
'photo-enhancer': {
|
||||
type: 'comparison',
|
||||
before: '/management/pages/home/sections/our-tools/photo-enhancer/before.jpg',
|
||||
after: '/management/pages/home/sections/our-tools/photo-enhancer/after.jpg',
|
||||
},
|
||||
'old-photo-restorer': {
|
||||
type: 'comparison',
|
||||
before: '/management/pages/home/sections/our-tools/old-photo-restorer/before.jpg',
|
||||
after: '/management/pages/home/sections/our-tools/old-photo-restorer/after.jpg',
|
||||
},
|
||||
'colorization': {
|
||||
type: 'comparison',
|
||||
before: '/management/pages/home/sections/our-tools/colorization/before.jpg',
|
||||
after: '/management/pages/home/sections/our-tools/colorization/after.jpg',
|
||||
},
|
||||
'cartoon-avatar': {
|
||||
type: 'comparison',
|
||||
before: '/management/pages/home/sections/our-tools/cartoon-avatar/before.jpg',
|
||||
after: '/management/pages/home/sections/our-tools/cartoon-avatar/after.jpg',
|
||||
},
|
||||
'object-eraser': {
|
||||
type: 'comparison',
|
||||
before: 'https://images.unsplash.com/photo-1507003211169-0a1dd7228f2d?w=800&auto=format&fit=crop&q=80',
|
||||
after: 'https://images.unsplash.com/photo-1500648767791-00dcc994a43e?w=800&auto=format&fit=crop&q=80',
|
||||
},
|
||||
'background-remover': {
|
||||
type: 'single',
|
||||
image: '/management/pages/home/sections/our-tools/background-remover/poster.jpg',
|
||||
badge: 'Alpha Matting',
|
||||
},
|
||||
'polaroid-maker': {
|
||||
type: 'single',
|
||||
image: '/management/pages/home/sections/our-tools/polaroid-maker/image.jpg',
|
||||
badge: 'Vintage Polaroid',
|
||||
},
|
||||
};
|
||||
|
||||
const matched = localDefaults[tool.slug];
|
||||
if (matched) {
|
||||
return {
|
||||
type: 'comparison',
|
||||
before: matched.before,
|
||||
after: matched.after,
|
||||
};
|
||||
}
|
||||
if (matched) return matched;
|
||||
|
||||
if (example && example.before && example.after) {
|
||||
return {
|
||||
@@ -285,7 +299,7 @@ export function ToolGridSection({
|
||||
const [searchQuery, setSearchQuery] = useState<string>('');
|
||||
const railRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
// Group tools by category
|
||||
// Group all tools by category
|
||||
const categorizedTools = useMemo(() => {
|
||||
const orderedCategoryIds = [
|
||||
'portrait-retouch',
|
||||
@@ -321,6 +335,14 @@ export function ToolGridSection({
|
||||
});
|
||||
}, [tools, searchQuery, locale]);
|
||||
|
||||
// Categories to display based on selectedCategory
|
||||
const displayedCategories = useMemo(() => {
|
||||
if (selectedCategory === 'all') {
|
||||
return categorizedTools;
|
||||
}
|
||||
return categorizedTools.filter((group) => group.id === selectedCategory);
|
||||
}, [categorizedTools, selectedCategory]);
|
||||
|
||||
// Smooth scroll rail for categories
|
||||
const scrollRail = (direction: 'left' | 'right') => {
|
||||
if (railRef.current) {
|
||||
@@ -331,57 +353,30 @@ export function ToolGridSection({
|
||||
}
|
||||
};
|
||||
|
||||
// Scroll to category section
|
||||
const handleCategoryClick = (catId: string) => {
|
||||
// Fluid category tab selection with smooth pill centering
|
||||
const handleCategoryClick = (
|
||||
catId: string,
|
||||
e?: React.MouseEvent<HTMLButtonElement>
|
||||
) => {
|
||||
setSelectedCategory(catId);
|
||||
if (searchQuery) setSearchQuery('');
|
||||
|
||||
if (catId === 'all') {
|
||||
const el = document.getElementById('tools-catalog');
|
||||
if (el) {
|
||||
el.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
||||
}
|
||||
} else {
|
||||
const el = document.getElementById(`category-${catId}`);
|
||||
if (el) {
|
||||
el.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
||||
}
|
||||
// Smoothly center the clicked pill in the scrolling rail
|
||||
if (e?.currentTarget) {
|
||||
e.currentTarget.scrollIntoView({
|
||||
behavior: 'smooth',
|
||||
inline: 'center',
|
||||
block: 'nearest',
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// Active category observer as user scrolls
|
||||
useEffect(() => {
|
||||
if (searchQuery) return;
|
||||
|
||||
const observer = new IntersectionObserver(
|
||||
(entries) => {
|
||||
entries.forEach((entry) => {
|
||||
if (entry.isIntersecting) {
|
||||
const id = entry.target.id.replace('category-', '');
|
||||
setSelectedCategory(id);
|
||||
}
|
||||
});
|
||||
},
|
||||
{
|
||||
rootMargin: '-30% 0px -60% 0px',
|
||||
threshold: 0,
|
||||
}
|
||||
);
|
||||
|
||||
categorizedTools.forEach((group) => {
|
||||
const el = document.getElementById(`category-${group.id}`);
|
||||
if (el) observer.observe(el);
|
||||
});
|
||||
|
||||
return () => observer.disconnect();
|
||||
}, [categorizedTools, searchQuery]);
|
||||
|
||||
return (
|
||||
<section id="tools-catalog" className="py-12 sm:py-16 bg-[#FAF8F5]">
|
||||
<section id="tools-catalog" className="py-10 sm:py-16 bg-[#FAF8F5]">
|
||||
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
|
||||
{/* Section Heading */}
|
||||
{(title || subtitle) && (
|
||||
<div className="text-center max-w-3xl mx-auto mb-10 sm:mb-14 space-y-3">
|
||||
<div className="text-center max-w-3xl mx-auto mb-8 sm:mb-12 space-y-3">
|
||||
{title && (
|
||||
<h2 className="text-3xl sm:text-4xl lg:text-5xl font-display font-black text-slate-900 tracking-tight">
|
||||
{resolveLocalised(title, locale)}
|
||||
@@ -395,18 +390,18 @@ export function ToolGridSection({
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Sticky Horizontal Scrolling Category Bar & Search */}
|
||||
{/* Sticky Fluid Horizontal Scrolling Category Bar & Search */}
|
||||
{(showCategoryFilter || showSearch) && (
|
||||
<div className="sticky top-[64px] sm:top-[72px] z-30 mb-12 -mx-4 sm:-mx-6 lg:-mx-8 px-4 sm:px-6 lg:px-8 py-3 bg-[#FAF8F5]/90 backdrop-blur-md border-y border-slate-200/80 shadow-[0_4px_20px_-10px_rgba(0,0,0,0.06)]">
|
||||
<div className="sticky top-[64px] sm:top-[72px] z-30 mb-10 -mx-4 sm:-mx-6 lg:-mx-8 px-4 sm:px-6 lg:px-8 py-3 bg-[#FAF8F5]/95 backdrop-blur-md border-y border-slate-200/80 shadow-[0_4px_20px_-10px_rgba(0,0,0,0.06)]">
|
||||
<div className="max-w-7xl mx-auto flex flex-col md:flex-row items-stretch md:items-center justify-between gap-3 sm:gap-4">
|
||||
{/* Category Rail with Smooth Scrolling */}
|
||||
{/* Category Rail with Fluid Scrolling */}
|
||||
{showCategoryFilter && (
|
||||
<div className="relative flex-1 flex items-center min-w-0">
|
||||
{/* Left Scroll Arrow */}
|
||||
<button
|
||||
onClick={() => scrollRail('left')}
|
||||
aria-label="Scroll categories left"
|
||||
className="hidden sm:flex items-center justify-center w-8 h-8 rounded-full bg-white border border-slate-200 text-slate-600 hover:text-slate-900 shadow-sm shrink-0 mr-1.5 transition-colors"
|
||||
className="hidden sm:flex items-center justify-center w-8 h-8 rounded-full bg-white border border-slate-200 text-slate-600 hover:text-slate-900 shadow-sm shrink-0 mr-1.5 transition-colors cursor-pointer"
|
||||
>
|
||||
<ChevronLeft className="w-4 h-4" />
|
||||
</button>
|
||||
@@ -419,13 +414,14 @@ export function ToolGridSection({
|
||||
>
|
||||
{/* All Categories Pill */}
|
||||
<button
|
||||
onClick={() => handleCategoryClick('all')}
|
||||
className={`shrink-0 flex items-center gap-2 px-4 py-2 rounded-full text-xs font-bold transition-all duration-200 shadow-sm ${
|
||||
onClick={(e) => handleCategoryClick('all', e)}
|
||||
className={`shrink-0 flex items-center gap-2 px-4 py-2 rounded-full text-xs font-bold transition-all duration-200 shadow-sm cursor-pointer ${
|
||||
selectedCategory === 'all' && !searchQuery
|
||||
? 'bg-blue-600 text-white shadow-blue-500/25 ring-2 ring-blue-500/30'
|
||||
? 'bg-blue-600 text-white shadow-blue-500/25 ring-2 ring-blue-500/30 scale-[1.02]'
|
||||
: 'bg-white text-slate-700 hover:text-slate-900 hover:bg-slate-50 border border-slate-200/90'
|
||||
}`}
|
||||
>
|
||||
<Layers className="w-3.5 h-3.5" />
|
||||
<span>All Categories</span>
|
||||
<span
|
||||
className={`text-[10px] font-mono px-1.5 py-0.2 rounded-full ${
|
||||
@@ -450,10 +446,10 @@ export function ToolGridSection({
|
||||
return (
|
||||
<button
|
||||
key={group.id}
|
||||
onClick={() => handleCategoryClick(group.id)}
|
||||
className={`shrink-0 flex items-center gap-2 px-3.5 py-2 rounded-full text-xs font-bold transition-all duration-200 shadow-sm ${
|
||||
onClick={(e) => handleCategoryClick(group.id, e)}
|
||||
className={`shrink-0 flex items-center gap-2 px-3.5 py-2 rounded-full text-xs font-bold transition-all duration-200 shadow-sm cursor-pointer ${
|
||||
isSelected
|
||||
? 'bg-blue-600 text-white shadow-blue-500/25 ring-2 ring-blue-500/30'
|
||||
? 'bg-blue-600 text-white shadow-blue-500/25 ring-2 ring-blue-500/30 scale-[1.02]'
|
||||
: 'bg-white text-slate-700 hover:text-slate-900 hover:bg-slate-50 border border-slate-200/90'
|
||||
}`}
|
||||
>
|
||||
@@ -479,7 +475,7 @@ export function ToolGridSection({
|
||||
<button
|
||||
onClick={() => scrollRail('right')}
|
||||
aria-label="Scroll categories right"
|
||||
className="hidden sm:flex items-center justify-center w-8 h-8 rounded-full bg-white border border-slate-200 text-slate-600 hover:text-slate-900 shadow-sm shrink-0 ml-1.5 transition-colors"
|
||||
className="hidden sm:flex items-center justify-center w-8 h-8 rounded-full bg-white border border-slate-200 text-slate-600 hover:text-slate-900 shadow-sm shrink-0 ml-1.5 transition-colors cursor-pointer"
|
||||
>
|
||||
<ChevronRight className="w-4 h-4" />
|
||||
</button>
|
||||
@@ -500,7 +496,7 @@ export function ToolGridSection({
|
||||
{searchQuery && (
|
||||
<button
|
||||
onClick={() => setSearchQuery('')}
|
||||
className="absolute right-3 top-1/2 -translate-y-1/2 text-slate-400 hover:text-slate-600"
|
||||
className="absolute right-3 top-1/2 -translate-y-1/2 text-slate-400 hover:text-slate-600 cursor-pointer"
|
||||
>
|
||||
<X className="w-3.5 h-3.5" />
|
||||
</button>
|
||||
@@ -523,7 +519,7 @@ export function ToolGridSection({
|
||||
</h3>
|
||||
<button
|
||||
onClick={() => setSearchQuery('')}
|
||||
className="text-xs font-mono font-bold text-blue-600 hover:text-blue-700 underline"
|
||||
className="text-xs font-mono font-bold text-blue-600 hover:text-blue-700 underline cursor-pointer"
|
||||
>
|
||||
Clear Search
|
||||
</button>
|
||||
@@ -542,11 +538,11 @@ export function ToolGridSection({
|
||||
</p>
|
||||
<p className="text-xs text-slate-500">
|
||||
Try searching for "blemish", "restoration",
|
||||
"background", or "avatar".
|
||||
"cutout", or "avatar".
|
||||
</p>
|
||||
<button
|
||||
onClick={() => setSearchQuery('')}
|
||||
className="mt-2 inline-flex items-center px-4 py-2 rounded-full bg-blue-600 text-white text-xs font-bold shadow-sm"
|
||||
className="mt-2 inline-flex items-center px-4 py-2 rounded-full bg-blue-600 text-white text-xs font-bold shadow-sm cursor-pointer"
|
||||
>
|
||||
View All Tools
|
||||
</button>
|
||||
@@ -554,9 +550,24 @@ export function ToolGridSection({
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
/* Categorized Tools Sections */
|
||||
<div className="space-y-14 sm:space-y-16">
|
||||
{categorizedTools.map((group) => {
|
||||
/* Categorized Tools Sections (Fluid, All 12 Tools Included) */
|
||||
<div className="space-y-12 sm:space-y-16">
|
||||
{/* Quick reset button if filtered to single category */}
|
||||
{selectedCategory !== 'all' && (
|
||||
<div className="flex items-center justify-between pb-2">
|
||||
<button
|
||||
onClick={() => setSelectedCategory('all')}
|
||||
className="inline-flex items-center gap-1.5 text-xs font-mono font-bold text-blue-600 hover:text-blue-700 bg-blue-50 border border-blue-200 px-3 py-1.5 rounded-full transition-colors cursor-pointer shadow-sm"
|
||||
>
|
||||
<span>← Show All {tools.length} Tools</span>
|
||||
</button>
|
||||
<span className="text-xs text-slate-400 font-mono">
|
||||
Filtered Category
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{displayedCategories.map((group) => {
|
||||
const theme = CATEGORY_THEMES[group.id];
|
||||
const catName = group.category
|
||||
? resolveLocalised(group.category.name, locale)
|
||||
@@ -569,7 +580,7 @@ export function ToolGridSection({
|
||||
<div
|
||||
key={group.id}
|
||||
id={`category-${group.id}`}
|
||||
className="scroll-mt-36 space-y-6"
|
||||
className="space-y-6"
|
||||
>
|
||||
{/* Category Header */}
|
||||
<div className="flex flex-col sm:flex-row sm:items-end justify-between gap-3 pb-4 border-b border-slate-200/90">
|
||||
|
||||
Reference in New Issue
Block a user