feat(tools): redesign tools directory with image-dominant cards, categorized layout, and smooth category scrolling
This commit is contained in:
@@ -1,8 +1,19 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import React, { useState, useMemo } from 'react';
|
import React, { useState, useMemo, useRef, useEffect } from 'react';
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
import { Search, ArrowRight, Wand2, Scissors, Smile, Palette, RefreshCcw } from 'lucide-react';
|
import {
|
||||||
|
Search,
|
||||||
|
ArrowRight,
|
||||||
|
Wand2,
|
||||||
|
Scissors,
|
||||||
|
Smile,
|
||||||
|
Palette,
|
||||||
|
Sparkles,
|
||||||
|
ChevronLeft,
|
||||||
|
ChevronRight,
|
||||||
|
X,
|
||||||
|
} from 'lucide-react';
|
||||||
import { ToolItem, CategoryItem, AppItem, resolveLocalised } from '@/types';
|
import { ToolItem, CategoryItem, AppItem, resolveLocalised } from '@/types';
|
||||||
|
|
||||||
interface ToolGridSectionProps {
|
interface ToolGridSectionProps {
|
||||||
@@ -18,62 +29,359 @@ interface ToolGridSectionProps {
|
|||||||
locale?: string;
|
locale?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ToolMediaConfig =
|
||||||
|
| { type: 'comparison'; before: string; after: string }
|
||||||
|
| { type: 'single'; image: string; badge: string };
|
||||||
|
|
||||||
|
// Media resolver for tool cards
|
||||||
|
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 }> = {
|
||||||
|
'blemish-remover': {
|
||||||
|
before: '/management/pages/home/sections/our-tools/blemish-remover/before.jpg',
|
||||||
|
after: '/management/pages/home/sections/our-tools/blemish-remover/after.jpg',
|
||||||
|
},
|
||||||
|
'teeth-whitener': {
|
||||||
|
before: '/management/pages/home/sections/our-tools/teeth-whitener/before.jpg',
|
||||||
|
after: '/management/pages/home/sections/our-tools/teeth-whitener/after.jpg',
|
||||||
|
},
|
||||||
|
'photo-enhancer': {
|
||||||
|
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': {
|
||||||
|
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': {
|
||||||
|
before: '/management/pages/home/sections/our-tools/colorization/before.jpg',
|
||||||
|
after: '/management/pages/home/sections/our-tools/colorization/after.jpg',
|
||||||
|
},
|
||||||
|
'cartoon-avatar': {
|
||||||
|
before: '/management/pages/home/sections/our-tools/cartoon-avatar/before.jpg',
|
||||||
|
after: '/management/pages/home/sections/our-tools/cartoon-avatar/after.jpg',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const matched = localDefaults[tool.slug];
|
||||||
|
if (matched) {
|
||||||
|
return {
|
||||||
|
type: 'comparison',
|
||||||
|
before: matched.before,
|
||||||
|
after: matched.after,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (example && example.before && example.after) {
|
||||||
|
return {
|
||||||
|
type: 'comparison',
|
||||||
|
before: example.before,
|
||||||
|
after: example.after,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
type: 'single',
|
||||||
|
image: example?.after || '/management/pages/home/sections/our-tools/blemish-remover/after.jpg',
|
||||||
|
badge: 'AI Studio',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Category design themes
|
||||||
|
const CATEGORY_THEMES: Record<
|
||||||
|
string,
|
||||||
|
{
|
||||||
|
icon: React.ReactNode;
|
||||||
|
color: string;
|
||||||
|
badgeBg: string;
|
||||||
|
border: string;
|
||||||
|
}
|
||||||
|
> = {
|
||||||
|
'portrait-retouch': {
|
||||||
|
icon: <Smile className="w-5 h-5 text-rose-500" />,
|
||||||
|
color: 'text-rose-600',
|
||||||
|
badgeBg: 'bg-rose-50 text-rose-700 border-rose-200',
|
||||||
|
border: 'border-rose-100',
|
||||||
|
},
|
||||||
|
'restoration': {
|
||||||
|
icon: <Sparkles className="w-5 h-5 text-indigo-500" />,
|
||||||
|
color: 'text-indigo-600',
|
||||||
|
badgeBg: 'bg-indigo-50 text-indigo-700 border-indigo-200',
|
||||||
|
border: 'border-indigo-100',
|
||||||
|
},
|
||||||
|
'background-cutout': {
|
||||||
|
icon: <Scissors className="w-5 h-5 text-emerald-500" />,
|
||||||
|
color: 'text-emerald-600',
|
||||||
|
badgeBg: 'bg-emerald-50 text-emerald-700 border-emerald-200',
|
||||||
|
border: 'border-emerald-100',
|
||||||
|
},
|
||||||
|
'creative-art': {
|
||||||
|
icon: <Palette className="w-5 h-5 text-amber-500" />,
|
||||||
|
color: 'text-amber-600',
|
||||||
|
badgeBg: 'bg-amber-50 text-amber-700 border-amber-200',
|
||||||
|
border: 'border-amber-100',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
// Interactive Before/After Card Image Component
|
||||||
|
function ToolCardImage({ tool, toolName }: { tool: ToolItem; toolName: string }) {
|
||||||
|
const [splitPos, setSplitPos] = useState<number>(50);
|
||||||
|
const media = getToolMedia(tool);
|
||||||
|
|
||||||
|
const handleMouseMove = (e: React.MouseEvent<HTMLDivElement>) => {
|
||||||
|
const rect = e.currentTarget.getBoundingClientRect();
|
||||||
|
const x = e.clientX - rect.left;
|
||||||
|
const pct = Math.max(5, Math.min(95, (x / rect.width) * 100));
|
||||||
|
setSplitPos(pct);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleMouseLeave = () => {
|
||||||
|
setSplitPos(50);
|
||||||
|
};
|
||||||
|
|
||||||
|
if (media.type === 'single') {
|
||||||
|
return (
|
||||||
|
<div className="relative w-full aspect-[4/3] rounded-2xl overflow-hidden bg-slate-950 select-none group/img shadow-inner">
|
||||||
|
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||||
|
<img
|
||||||
|
src={media.image}
|
||||||
|
alt={toolName}
|
||||||
|
loading="lazy"
|
||||||
|
decoding="async"
|
||||||
|
className="absolute inset-0 w-full h-full object-cover transition-transform duration-500 group-hover:scale-105"
|
||||||
|
/>
|
||||||
|
{/* Floating badge */}
|
||||||
|
<span className="absolute bottom-2.5 right-2.5 bg-blue-600/90 backdrop-blur-md text-[9px] font-mono font-bold uppercase tracking-wider text-white px-2 py-0.5 rounded-md border border-white/20 pointer-events-none shadow-sm">
|
||||||
|
{media.badge}
|
||||||
|
</span>
|
||||||
|
<span className="absolute top-2.5 right-2.5 bg-white/90 backdrop-blur-md text-[9.5px] font-mono font-bold text-slate-800 px-2.5 py-0.5 rounded-full border border-slate-200 pointer-events-none shadow-sm opacity-0 group-hover:opacity-100 transition-opacity duration-200">
|
||||||
|
Try Tool ↗
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
onMouseMove={handleMouseMove}
|
||||||
|
onMouseLeave={handleMouseLeave}
|
||||||
|
className="relative w-full aspect-[4/3] rounded-2xl overflow-hidden bg-slate-950 select-none cursor-ew-resize group/img shadow-inner"
|
||||||
|
>
|
||||||
|
{/* Enhanced / After Image (Underneath) */}
|
||||||
|
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||||
|
<img
|
||||||
|
src={media.after}
|
||||||
|
alt={`${toolName} after`}
|
||||||
|
loading="lazy"
|
||||||
|
decoding="async"
|
||||||
|
className="absolute inset-0 w-full h-full object-cover transition-transform duration-500 group-hover:scale-105"
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* Original / Before Image (Clipped overlay) */}
|
||||||
|
<div
|
||||||
|
className="absolute inset-0 overflow-hidden"
|
||||||
|
style={{
|
||||||
|
clipPath: `polygon(0 0, ${splitPos}% 0, ${splitPos}% 100%, 0 100%)`,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||||
|
<img
|
||||||
|
src={media.before}
|
||||||
|
alt={`${toolName} before`}
|
||||||
|
loading="lazy"
|
||||||
|
decoding="async"
|
||||||
|
className="absolute inset-0 w-full h-full object-cover transition-transform duration-500 group-hover:scale-105"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Vertical Slider Divider */}
|
||||||
|
<div
|
||||||
|
className="absolute top-0 bottom-0 w-[2px] bg-white shadow-[0_0_8px_rgba(0,0,0,0.6)] pointer-events-none"
|
||||||
|
style={{ left: `${splitPos}%`, transform: 'translateX(-50%)' }}
|
||||||
|
>
|
||||||
|
{/* Sleek handle pill */}
|
||||||
|
<div className="absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-6 h-6 rounded-full bg-white/95 backdrop-blur-sm text-slate-800 shadow-md flex items-center justify-center border border-slate-300">
|
||||||
|
<div className="flex items-center gap-[2px]">
|
||||||
|
<div className="w-0 h-0 border-y-[3px] border-y-transparent border-r-[4px] border-r-slate-700" />
|
||||||
|
<div className="w-0 h-0 border-y-[3px] border-y-transparent border-l-[4px] border-l-slate-700" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Floating badges */}
|
||||||
|
<span className="absolute bottom-2.5 left-2.5 bg-black/60 backdrop-blur-md text-[9px] font-mono font-bold uppercase tracking-wider text-white px-2 py-0.5 rounded-md border border-white/10 pointer-events-none shadow-sm">
|
||||||
|
Before
|
||||||
|
</span>
|
||||||
|
<span className="absolute bottom-2.5 right-2.5 bg-blue-600/90 backdrop-blur-md text-[9px] font-mono font-bold uppercase tracking-wider text-white px-2 py-0.5 rounded-md border border-white/20 pointer-events-none shadow-sm">
|
||||||
|
CRE AI
|
||||||
|
</span>
|
||||||
|
<span className="absolute top-2.5 right-2.5 bg-white/90 backdrop-blur-md text-[9.5px] font-mono font-bold text-slate-800 px-2.5 py-0.5 rounded-full border border-slate-200 pointer-events-none shadow-sm opacity-0 group-hover:opacity-100 transition-opacity duration-200">
|
||||||
|
Try Tool ↗
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Single Image-Dominant Tool Card Component (~75% Image, Minimal Text)
|
||||||
|
function ToolCard({ tool, locale }: { tool: ToolItem; locale: string }) {
|
||||||
|
const toolName = resolveLocalised(tool.name, locale);
|
||||||
|
const toolSummary = resolveLocalised(tool.summary, locale);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Link
|
||||||
|
href={`/tools/${tool.slug}`}
|
||||||
|
className="group block bg-white rounded-3xl p-3 sm:p-3.5 border border-slate-900/[0.08] hover:border-blue-400 shadow-cream-sm hover:shadow-cream-md transition-all duration-300 hover:-translate-y-1"
|
||||||
|
>
|
||||||
|
{/* Image Dominant Preview (~75% of visual area) */}
|
||||||
|
<ToolCardImage tool={tool} toolName={toolName} />
|
||||||
|
|
||||||
|
{/* Minimalist Info Area: Only Title & Subtitle */}
|
||||||
|
<div className="mt-3.5 px-1 pb-1">
|
||||||
|
<div className="flex items-center justify-between gap-2">
|
||||||
|
<h4 className="text-base sm:text-lg font-display font-bold text-slate-900 group-hover:text-blue-600 transition-colors truncate">
|
||||||
|
{toolName}
|
||||||
|
</h4>
|
||||||
|
<div className="w-6 h-6 rounded-full bg-slate-100 flex items-center justify-center text-slate-400 group-hover:bg-blue-600 group-hover:text-white transition-all duration-200 shrink-0 shadow-sm">
|
||||||
|
<ArrowRight className="w-3.5 h-3.5 group-hover:translate-x-0.5 transition-transform" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p className="mt-1 text-xs sm:text-sm text-slate-500 line-clamp-2 leading-relaxed">
|
||||||
|
{toolSummary}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</Link>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export function ToolGridSection({
|
export function ToolGridSection({
|
||||||
title,
|
title,
|
||||||
subtitle,
|
subtitle,
|
||||||
tools = [],
|
tools = [],
|
||||||
categories = [],
|
categories = [],
|
||||||
apps = [],
|
showSearch = true,
|
||||||
showSearch = false,
|
showCategoryFilter = true,
|
||||||
showCategoryFilter = false,
|
|
||||||
limit,
|
|
||||||
locale = 'en',
|
locale = 'en',
|
||||||
}: ToolGridSectionProps) {
|
}: ToolGridSectionProps) {
|
||||||
const [selectedCategory, setSelectedCategory] = useState<string>('all');
|
const [selectedCategory, setSelectedCategory] = useState<string>('all');
|
||||||
const [searchQuery, setSearchQuery] = useState<string>('');
|
const [searchQuery, setSearchQuery] = useState<string>('');
|
||||||
|
const railRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
const appMap = useMemo(() => new Map(apps.map((a) => [a.id, a])), [apps]);
|
// Group tools by category
|
||||||
|
const categorizedTools = useMemo(() => {
|
||||||
|
const orderedCategoryIds = [
|
||||||
|
'portrait-retouch',
|
||||||
|
'restoration',
|
||||||
|
'background-cutout',
|
||||||
|
'creative-art',
|
||||||
|
];
|
||||||
|
|
||||||
const filteredTools = useMemo(() => {
|
const catMap = new Map<string, CategoryItem>();
|
||||||
let list = tools;
|
categories.forEach((cat) => catMap.set(cat.id, cat));
|
||||||
if (selectedCategory !== 'all') {
|
|
||||||
list = list.filter((t) => t.category === selectedCategory);
|
return orderedCategoryIds
|
||||||
}
|
.map((catId) => {
|
||||||
if (searchQuery.trim()) {
|
const cat = catMap.get(catId);
|
||||||
const q = searchQuery.toLowerCase();
|
const catTools = tools.filter((t) => t.category === catId);
|
||||||
list = list.filter((t) => {
|
return {
|
||||||
const name = resolveLocalised(t.name, locale).toLowerCase();
|
id: catId,
|
||||||
const summary = resolveLocalised(t.summary, locale).toLowerCase();
|
category: cat,
|
||||||
return name.includes(q) || summary.includes(q);
|
tools: catTools,
|
||||||
|
};
|
||||||
|
})
|
||||||
|
.filter((group) => group.tools.length > 0);
|
||||||
|
}, [categories, tools]);
|
||||||
|
|
||||||
|
// Filter tools when search query is active
|
||||||
|
const searchResults = useMemo(() => {
|
||||||
|
if (!searchQuery.trim()) return null;
|
||||||
|
const q = searchQuery.toLowerCase();
|
||||||
|
return tools.filter((t) => {
|
||||||
|
const name = resolveLocalised(t.name, locale).toLowerCase();
|
||||||
|
const summary = resolveLocalised(t.summary, locale).toLowerCase();
|
||||||
|
return name.includes(q) || summary.includes(q);
|
||||||
|
});
|
||||||
|
}, [tools, searchQuery, locale]);
|
||||||
|
|
||||||
|
// Smooth scroll rail for categories
|
||||||
|
const scrollRail = (direction: 'left' | 'right') => {
|
||||||
|
if (railRef.current) {
|
||||||
|
railRef.current.scrollBy({
|
||||||
|
left: direction === 'left' ? -220 : 220,
|
||||||
|
behavior: 'smooth',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (limit && limit > 0) {
|
|
||||||
list = list.slice(0, limit);
|
|
||||||
}
|
|
||||||
return list;
|
|
||||||
}, [tools, selectedCategory, searchQuery, limit, locale]);
|
|
||||||
|
|
||||||
const getCategoryIcon = (catId: string) => {
|
|
||||||
switch (catId) {
|
|
||||||
case 'portrait-retouch':
|
|
||||||
return <Smile className="w-4 h-4 text-blue-600" />;
|
|
||||||
case 'restoration':
|
|
||||||
return <RefreshCcw className="w-4 h-4 text-purple-600" />;
|
|
||||||
case 'background-cutout':
|
|
||||||
return <Scissors className="w-4 h-4 text-emerald-600" />;
|
|
||||||
case 'creative-art':
|
|
||||||
return <Palette className="w-4 h-4 text-pink-600" />;
|
|
||||||
default:
|
|
||||||
return <Wand2 className="w-4 h-4 text-blue-600" />;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Scroll to category section
|
||||||
|
const handleCategoryClick = (catId: string) => {
|
||||||
|
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' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 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 (
|
return (
|
||||||
<section className="py-20 sm:py-24 lg:py-28 bg-[#FAF8F5] border-t border-slate-900/[0.08]">
|
<section id="tools-catalog" className="py-12 sm:py-16 bg-[#FAF8F5]">
|
||||||
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
|
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
|
||||||
{/* Section Heading */}
|
{/* Section Heading */}
|
||||||
{(title || subtitle) && (
|
{(title || subtitle) && (
|
||||||
<div className="text-center max-w-3xl mx-auto mb-14 space-y-3">
|
<div className="text-center max-w-3xl mx-auto mb-10 sm:mb-14 space-y-3">
|
||||||
{title && (
|
{title && (
|
||||||
<h2 className="text-3xl sm:text-4xl lg:text-5xl font-display font-black text-slate-900 tracking-tight">
|
<h2 className="text-3xl sm:text-4xl lg:text-5xl font-display font-black text-slate-900 tracking-tight">
|
||||||
{resolveLocalised(title, locale)}
|
{resolveLocalised(title, locale)}
|
||||||
@@ -87,143 +395,223 @@ export function ToolGridSection({
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Search & Filters */}
|
{/* Sticky Horizontal Scrolling Category Bar & Search */}
|
||||||
{(showSearch || showCategoryFilter) && (
|
{(showCategoryFilter || showSearch) && (
|
||||||
<div className="mb-12 flex flex-col md:flex-row items-stretch md:items-center justify-between gap-4">
|
<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)]">
|
||||||
{showCategoryFilter && categories.length > 0 && (
|
<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">
|
||||||
<div className="flex flex-wrap items-center gap-2">
|
{/* Category Rail with Smooth Scrolling */}
|
||||||
<button
|
{showCategoryFilter && (
|
||||||
onClick={() => setSelectedCategory('all')}
|
<div className="relative flex-1 flex items-center min-w-0">
|
||||||
className={`px-4 py-2 rounded-full text-xs font-bold transition-all duration-200 shadow-sm ${
|
{/* Left Scroll Arrow */}
|
||||||
selectedCategory === 'all'
|
|
||||||
? 'bg-blue-600 text-white shadow-blue-500/20'
|
|
||||||
: 'bg-white text-slate-700 border border-slate-200 hover:bg-slate-50'
|
|
||||||
}`}
|
|
||||||
>
|
|
||||||
All Tools ({tools.length})
|
|
||||||
</button>
|
|
||||||
{categories.map((cat) => (
|
|
||||||
<button
|
<button
|
||||||
key={cat.id}
|
onClick={() => scrollRail('left')}
|
||||||
onClick={() => setSelectedCategory(cat.id)}
|
aria-label="Scroll categories left"
|
||||||
className={`flex items-center gap-1.5 px-3.5 py-2 rounded-full text-xs font-bold transition-all duration-200 shadow-sm ${
|
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"
|
||||||
selectedCategory === cat.id
|
|
||||||
? 'bg-blue-600 text-white shadow-blue-500/20'
|
|
||||||
: 'bg-white text-slate-700 border border-slate-200 hover:bg-slate-50'
|
|
||||||
}`}
|
|
||||||
>
|
>
|
||||||
<span>{getCategoryIcon(cat.id)}</span>
|
<ChevronLeft className="w-4 h-4" />
|
||||||
<span>{resolveLocalised(cat.name, locale)}</span>
|
|
||||||
</button>
|
</button>
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{showSearch && (
|
{/* Horizontal Scrollable Categories Container */}
|
||||||
<div className="relative w-full md:w-80">
|
<div
|
||||||
<Search className="w-4 h-4 absolute left-3.5 top-1/2 -translate-y-1/2 text-slate-400" />
|
ref={railRef}
|
||||||
<input
|
style={{ WebkitOverflowScrolling: 'touch' }}
|
||||||
type="text"
|
className="flex items-center gap-2 overflow-x-auto no-scrollbar scroll-smooth py-1 w-full touch-pan-x"
|
||||||
placeholder="Search AI photo tools..."
|
>
|
||||||
value={searchQuery}
|
{/* All Categories Pill */}
|
||||||
onChange={(e) => setSearchQuery(e.target.value)}
|
<button
|
||||||
className="w-full pl-10 pr-4 py-2.5 rounded-full text-xs sm:text-sm border border-slate-300 bg-white text-slate-900 placeholder-slate-400 focus:outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500 shadow-sm"
|
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 ${
|
||||||
</div>
|
selectedCategory === 'all' && !searchQuery
|
||||||
)}
|
? 'bg-blue-600 text-white shadow-blue-500/25 ring-2 ring-blue-500/30'
|
||||||
|
: 'bg-white text-slate-700 hover:text-slate-900 hover:bg-slate-50 border border-slate-200/90'
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
<span>All Categories</span>
|
||||||
|
<span
|
||||||
|
className={`text-[10px] font-mono px-1.5 py-0.2 rounded-full ${
|
||||||
|
selectedCategory === 'all' && !searchQuery
|
||||||
|
? 'bg-white/20 text-white'
|
||||||
|
: 'bg-slate-100 text-slate-600'
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{tools.length}
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
{/* 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 (
|
||||||
|
<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 ${
|
||||||
|
isSelected
|
||||||
|
? 'bg-blue-600 text-white shadow-blue-500/25 ring-2 ring-blue-500/30'
|
||||||
|
: 'bg-white text-slate-700 hover:text-slate-900 hover:bg-slate-50 border border-slate-200/90'
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
<span className={isSelected ? 'text-white' : ''}>
|
||||||
|
{theme?.icon || <Wand2 className="w-4 h-4" />}
|
||||||
|
</span>
|
||||||
|
<span>{catName}</span>
|
||||||
|
<span
|
||||||
|
className={`text-[10px] font-mono px-1.5 py-0.2 rounded-full ${
|
||||||
|
isSelected
|
||||||
|
? 'bg-white/20 text-white'
|
||||||
|
: 'bg-slate-100 text-slate-600'
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{group.tools.length}
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Right Scroll Arrow */}
|
||||||
|
<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"
|
||||||
|
>
|
||||||
|
<ChevronRight className="w-4 h-4" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Integrated Search Input */}
|
||||||
|
{showSearch && (
|
||||||
|
<div className="relative w-full md:w-72 shrink-0">
|
||||||
|
<Search className="w-4 h-4 absolute left-3.5 top-1/2 -translate-y-1/2 text-slate-400 pointer-events-none" />
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
placeholder="Search AI photo tools..."
|
||||||
|
value={searchQuery}
|
||||||
|
onChange={(e) => 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 && (
|
||||||
|
<button
|
||||||
|
onClick={() => setSearchQuery('')}
|
||||||
|
className="absolute right-3 top-1/2 -translate-y-1/2 text-slate-400 hover:text-slate-600"
|
||||||
|
>
|
||||||
|
<X className="w-3.5 h-3.5" />
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Tools Cards Grid with Visual Image Previews */}
|
{/* Content: Categorized Sections or Search Results */}
|
||||||
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-7 sm:gap-8">
|
{searchResults ? (
|
||||||
{filteredTools.map((tool) => {
|
/* Search Results View */
|
||||||
const homeApp = appMap.get(tool.homeApp);
|
<div className="space-y-6">
|
||||||
const example = tool.content?.examples?.[0];
|
<div className="flex items-center justify-between pb-3 border-b border-slate-200">
|
||||||
|
<h3 className="text-xl font-display font-bold text-slate-900">
|
||||||
return (
|
Found {searchResults.length}{' '}
|
||||||
<div
|
{searchResults.length === 1 ? 'tool' : 'tools'} matching "
|
||||||
key={tool.id}
|
{searchQuery}"
|
||||||
className="group relative bg-white rounded-3xl p-5 sm:p-6 border border-slate-900/[0.08] hover:border-blue-400 shadow-cream-sm hover:shadow-cream-md transition-all duration-300 flex flex-col justify-between"
|
</h3>
|
||||||
|
<button
|
||||||
|
onClick={() => setSearchQuery('')}
|
||||||
|
className="text-xs font-mono font-bold text-blue-600 hover:text-blue-700 underline"
|
||||||
>
|
>
|
||||||
<div>
|
Clear Search
|
||||||
{/* Visual Before/After Preview Card */}
|
</button>
|
||||||
{example ? (
|
</div>
|
||||||
<div className="relative aspect-[16/10] rounded-2xl overflow-hidden mb-4 bg-slate-950 border border-slate-200 shadow-inner group/thumb">
|
|
||||||
<div className="grid grid-cols-2 h-full w-full">
|
|
||||||
<div className="relative h-full overflow-hidden border-r border-white/20">
|
|
||||||
{/* eslint-disable-next-line @next/next/no-img-element */}
|
|
||||||
<img
|
|
||||||
src={example.before}
|
|
||||||
alt="Before preview"
|
|
||||||
loading="lazy"
|
|
||||||
className="h-full w-full object-cover"
|
|
||||||
/>
|
|
||||||
<span className="absolute bottom-1.5 left-1.5 bg-black/80 backdrop-blur-md px-1.5 py-0.5 rounded text-[8.5px] font-mono font-bold text-white">
|
|
||||||
Before
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div className="relative h-full overflow-hidden">
|
|
||||||
{/* eslint-disable-next-line @next/next/no-img-element */}
|
|
||||||
<img
|
|
||||||
src={example.after}
|
|
||||||
alt="After preview"
|
|
||||||
loading="lazy"
|
|
||||||
className="h-full w-full object-cover group-hover:scale-105 transition-transform duration-500"
|
|
||||||
/>
|
|
||||||
<span className="absolute bottom-1.5 right-1.5 bg-blue-600/90 backdrop-blur-md px-1.5 py-0.5 rounded text-[8.5px] font-mono font-bold text-white shadow-sm">
|
|
||||||
CRE AI
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
) : null}
|
|
||||||
|
|
||||||
{/* Category Tag & Icon */}
|
{searchResults.length > 0 ? (
|
||||||
<div className="flex items-center justify-between mb-3">
|
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-3 gap-6 sm:gap-7">
|
||||||
<span className="text-[10.5px] font-mono font-bold uppercase tracking-wider text-blue-700 bg-blue-50 px-2.5 py-0.5 rounded-lg border border-blue-200">
|
{searchResults.map((tool) => (
|
||||||
{tool.category}
|
<ToolCard key={tool.id} tool={tool} locale={locale} />
|
||||||
</span>
|
))}
|
||||||
<div className="w-8 h-8 rounded-xl bg-slate-100 border border-slate-200 flex items-center justify-center text-slate-700 group-hover:scale-110 group-hover:border-blue-300 transition-all duration-200">
|
</div>
|
||||||
{getCategoryIcon(tool.category)}
|
) : (
|
||||||
|
<div className="text-center py-16 text-slate-500 space-y-3 font-mono">
|
||||||
|
<p className="font-bold text-slate-800 text-base">
|
||||||
|
No photo tools found matching "{searchQuery}"
|
||||||
|
</p>
|
||||||
|
<p className="text-xs text-slate-500">
|
||||||
|
Try searching for "blemish", "restoration",
|
||||||
|
"background", 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"
|
||||||
|
>
|
||||||
|
View All Tools
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
/* Categorized Tools Sections */
|
||||||
|
<div className="space-y-14 sm:space-y-16">
|
||||||
|
{categorizedTools.map((group) => {
|
||||||
|
const theme = CATEGORY_THEMES[group.id];
|
||||||
|
const catName = group.category
|
||||||
|
? resolveLocalised(group.category.name, locale)
|
||||||
|
: group.id;
|
||||||
|
const catDesc = group.category
|
||||||
|
? resolveLocalised(group.category.description, locale)
|
||||||
|
: '';
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
key={group.id}
|
||||||
|
id={`category-${group.id}`}
|
||||||
|
className="scroll-mt-36 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">
|
||||||
|
<div className="flex items-center gap-3">
|
||||||
|
<div
|
||||||
|
className={`w-11 h-11 rounded-2xl flex items-center justify-center bg-white shadow-sm border border-slate-200/80 shrink-0`}
|
||||||
|
>
|
||||||
|
{theme?.icon || <Wand2 className="w-5 h-5 text-blue-600" />}
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<div className="flex items-center gap-2.5">
|
||||||
|
<h3 className="text-xl sm:text-2xl font-display font-black text-slate-900 tracking-tight">
|
||||||
|
{catName}
|
||||||
|
</h3>
|
||||||
|
<span
|
||||||
|
className={`text-xs font-mono font-bold px-2.5 py-0.5 rounded-full border ${
|
||||||
|
theme?.badgeBg ||
|
||||||
|
'bg-slate-100 text-slate-700 border-slate-200'
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{group.tools.length}{' '}
|
||||||
|
{group.tools.length === 1 ? 'tool' : 'tools'}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
{catDesc && (
|
||||||
|
<p className="text-xs sm:text-sm text-slate-500 mt-0.5">
|
||||||
|
{catDesc}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h3 className="text-lg font-display font-bold text-slate-900 group-hover:text-blue-600 transition-colors">
|
{/* Category Tools Grid with Image-Dominant Cards */}
|
||||||
{resolveLocalised(tool.name, locale)}
|
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-3 gap-6 sm:gap-7">
|
||||||
</h3>
|
{group.tools.map((tool) => (
|
||||||
|
<ToolCard key={tool.id} tool={tool} locale={locale} />
|
||||||
<p className="mt-2 text-xs text-slate-600 line-clamp-2 leading-relaxed font-normal">
|
))}
|
||||||
{resolveLocalised(tool.summary, locale)}
|
</div>
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
|
);
|
||||||
<div className="mt-5 pt-4 border-t border-slate-100 space-y-3">
|
})}
|
||||||
{homeApp && (
|
|
||||||
<div className="text-[11px] font-mono text-slate-500 flex items-center justify-between">
|
|
||||||
<span>Home App:</span>
|
|
||||||
<span className="font-bold text-slate-700 truncate max-w-[140px]">
|
|
||||||
{resolveLocalised(homeApp.name, locale)}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<Link
|
|
||||||
href={`/tools/${tool.slug}`}
|
|
||||||
className="w-full inline-flex items-center justify-center gap-2 py-3 rounded-full text-xs font-bold text-white bg-blue-600 hover:bg-blue-700 shadow-sm shadow-blue-500/20 transition-all duration-200"
|
|
||||||
>
|
|
||||||
<span>Try Free Online</span>
|
|
||||||
<ArrowRight className="w-3.5 h-3.5 group-hover:translate-x-1 transition-transform" />
|
|
||||||
</Link>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{filteredTools.length === 0 && (
|
|
||||||
<div className="text-center py-16 text-slate-500 space-y-2 font-mono">
|
|
||||||
<p className="font-bold">No photo tools found matching "{searchQuery}"</p>
|
|
||||||
<p className="text-xs">Try searching for "blemish", "background", "photo", or clear filters.</p>
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user