fix(tools): refine tool grid header, mobile touch slider scrolling, and remove duplicates

This commit is contained in:
2026-11-07 12:44:57 +05:30
parent d273fb0489
commit 39fdb0aae1
3 changed files with 214 additions and 163 deletions
+162 -159
View File
@@ -12,10 +12,7 @@ import {
Sparkles,
X,
Layers,
ShieldCheck,
Zap,
Smartphone,
SlidersHorizontal,
ChevronRight,
RotateCcw,
} from 'lucide-react';
@@ -227,35 +224,63 @@ function ToolCardImage({ tool, toolName }: { tool: ToolItem; toolName: string })
setSplitPos(pct);
}, []);
const handlePointerDown = (e: React.PointerEvent<HTMLDivElement>) => {
if (media.type !== 'comparison') return;
const startDragging = useCallback((clientX: number, target: HTMLElement, pointerId: number) => {
isDraggingRef.current = true;
try {
e.currentTarget.setPointerCapture(e.pointerId);
target.setPointerCapture(pointerId);
} catch {}
updatePosition(e.clientX);
updatePosition(clientX);
}, [updatePosition]);
// On desktop with mouse, clicking anywhere on the stage moves the slider.
// On phones/touch screens, touching the card does NOT move the slider,
// allowing completely unobstructed vertical page scrolling!
const handleContainerPointerDown = (e: React.PointerEvent<HTMLDivElement>) => {
if (media.type !== 'comparison') return;
if (e.pointerType !== 'mouse' || e.button !== 0) return;
startDragging(e.clientX, e.currentTarget, e.pointerId);
};
const handlePointerMove = (e: React.PointerEvent<HTMLDivElement>) => {
const handleContainerPointerMove = (e: React.PointerEvent<HTMLDivElement>) => {
if (media.type !== 'comparison') return;
if (isDraggingRef.current || e.pointerType === 'mouse') {
if (e.pointerType === 'mouse' && !isDraggingRef.current) {
updatePosition(e.clientX);
}
};
const handlePointerUp = (e: React.PointerEvent<HTMLDivElement>) => {
isDraggingRef.current = false;
try {
e.currentTarget.releasePointerCapture(e.pointerId);
} catch {}
};
const handlePointerLeave = (e: React.PointerEvent<HTMLDivElement>) => {
const handleContainerPointerLeave = (e: React.PointerEvent<HTMLDivElement>) => {
if (e.pointerType === 'mouse' && !isDraggingRef.current) {
setSplitPos(50);
}
};
// Dedicated Handle Button Pointer Handlers (Phone Touch & Mouse Dragging)
const handleHandlePointerDown = (e: React.PointerEvent<HTMLDivElement>) => {
if (media.type !== 'comparison') return;
if (e.button !== 0 && e.pointerType === 'mouse') return;
e.stopPropagation();
startDragging(e.clientX, e.currentTarget, e.pointerId);
};
const handleHandlePointerMove = (e: React.PointerEvent<HTMLDivElement>) => {
if (media.type !== 'comparison') return;
if (isDraggingRef.current) {
e.stopPropagation();
updatePosition(e.clientX);
}
};
const handleHandlePointerUp = (e: React.PointerEvent<HTMLDivElement>) => {
if (media.type !== 'comparison') return;
if (isDraggingRef.current) {
e.stopPropagation();
isDraggingRef.current = false;
try {
e.currentTarget.releasePointerCapture(e.pointerId);
} catch {}
}
};
// 1. VIDEO TOOL (Background Remover)
if (media.type === 'video') {
return (
@@ -294,12 +319,11 @@ function ToolCardImage({ tool, toolName }: { tool: ToolItem; toolName: string })
return (
<div
ref={containerRef}
onPointerDown={handlePointerDown}
onPointerMove={handlePointerMove}
onPointerUp={handlePointerUp}
onPointerCancel={handlePointerUp}
onPointerLeave={handlePointerLeave}
className="relative w-full aspect-[4/3] rounded-2xl overflow-hidden bg-paper-2 select-none cursor-ew-resize group/img shadow-inner touch-none"
onPointerDown={handleContainerPointerDown}
onPointerMove={handleContainerPointerMove}
onPointerLeave={handleContainerPointerLeave}
className="relative w-full aspect-[4/3] rounded-2xl overflow-hidden bg-paper-2 select-none cursor-ew-resize group/img shadow-inner touch-pan-y"
style={{ touchAction: 'pan-y' }}
>
{/* Enhanced / After Image (Underneath) */}
{/* eslint-disable-next-line @next/next/no-img-element */}
@@ -329,16 +353,27 @@ function ToolCardImage({ tool, toolName }: { tool: ToolItem; toolName: string })
/>
</div>
{/* Vertical Slider Divider Line */}
{/* Vertical Slider Divider Line (pointer-events-none so it doesn't block vertical scrolling) */}
<div
className="absolute top-0 bottom-0 w-[2px] bg-paper-hi shadow-md pointer-events-none z-10"
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-paper-hi text-ink shadow-md flex items-center justify-center border border-rule">
<div className="flex items-center gap-[2px]">
<div className="w-0 h-0 border-y-[3px] border-y-transparent border-r-[4px] border-r-ink" />
<div className="w-0 h-0 border-y-[3px] border-y-transparent border-l-[4px] border-l-ink" />
{/* Dedicated Tactile Handle Button: Phone touch activates ONLY on this button */}
<div
onPointerDown={handleHandlePointerDown}
onPointerMove={handleHandlePointerMove}
onPointerUp={handleHandlePointerUp}
onPointerCancel={handleHandlePointerUp}
role="slider"
aria-label="Before and after transformation slider"
aria-valuenow={Math.round(splitPos)}
tabIndex={0}
style={{ touchAction: 'none' }}
className="absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-8 h-8 rounded-full bg-paper-hi text-ink shadow-md flex items-center justify-center border border-rule pointer-events-auto cursor-ew-resize touch-none before:absolute before:-inset-3 before:content-['']"
>
<div className="flex items-center gap-[2px] pointer-events-none">
<div className="w-0 h-0 border-y-[3.5px] border-y-transparent border-r-[4.5px] border-r-ink" />
<div className="w-0 h-0 border-y-[3.5px] border-y-transparent border-l-[4.5px] border-l-ink" />
</div>
</div>
</div>
@@ -480,14 +515,6 @@ export function ToolGridSection({
return categorizedTools.find((g) => g.id === selectedCategory);
}, [categorizedTools, selectedCategory]);
// Categories to display
const displayedCategories = useMemo(() => {
if (selectedCategory === 'all') {
return categorizedTools;
}
return categorizedTools.filter((group) => group.id === selectedCategory);
}, [categorizedTools, selectedCategory]);
// If this is a simple embedded grid (e.g., inside an App detail page), render standard container
if (!showCategoryFilter) {
return (
@@ -537,25 +564,11 @@ export function ToolGridSection({
{/* Top: Header, Search, Categories Nav */}
<div className="space-y-6">
{/* Studio Brand & Directory Identity */}
<div className="flex items-center justify-between pb-3.5 border-b border-rule">
<div className="flex items-center gap-2.5">
<div className="w-8 h-8 rounded-xl bg-accent/10 border border-accent/20 flex items-center justify-center text-accent shadow-2xs">
<SlidersHorizontal className="w-4 h-4" />
</div>
<div>
<span className="text-xs font-semibold text-ink font-body block leading-tight">
Studio Directory
</span>
<span className="text-[11px] text-muted font-body">
12 neural models
</span>
</div>
</div>
<span className="inline-flex items-center gap-1.5 px-2.5 py-0.5 rounded-full bg-emerald-500/10 border border-emerald-500/20 text-emerald-600 text-[10px] font-semibold font-body">
<span className="w-1.5 h-1.5 rounded-full bg-emerald-500 animate-pulse" />
<span>Ready</span>
</span>
{/* Categories Header */}
<div className="pb-3.5 border-b border-rule">
<h2 className="text-sm font-bold text-ink font-body">
Categories
</h2>
</div>
{/* Instant Search Bar with shortcut hint */}
@@ -564,7 +577,7 @@ export function ToolGridSection({
<Search className="w-3.5 h-3.5 absolute left-3.5 top-1/2 -translate-y-1/2 text-muted pointer-events-none" />
<input
type="text"
placeholder="Search tools & models..."
placeholder="Search tools..."
value={searchQuery}
onChange={(e) => setSearchQuery(e.target.value)}
className="w-full pl-9 pr-8 py-2.5 rounded-2xl text-xs border border-rule bg-paper text-ink placeholder:text-muted focus:outline-none focus:border-accent focus:ring-2 focus:ring-accent/20 shadow-2xs font-body transition-colors"
@@ -587,8 +600,8 @@ export function ToolGridSection({
{/* Categories Navigation */}
<div className="space-y-2">
<div className="flex items-center justify-between px-1 text-[11px] font-semibold text-muted uppercase tracking-wider font-body">
<span>Workspaces</span>
<div className="flex items-center justify-between px-1 font-body">
<span className="text-xs font-bold text-ink uppercase tracking-wider">Workspaces</span>
{(selectedCategory !== 'all' || searchQuery) && (
<button
onClick={() => {
@@ -681,20 +694,8 @@ export function ToolGridSection({
</div>
{/* Bottom: GPU RAM Ephemeral Telemetry & Native App Suite Link */}
{/* Bottom: Native App Suite Link */}
<div className="pt-4 border-t border-rule space-y-3">
<div className="p-3.5 rounded-2xl bg-paper border border-rule space-y-1.5">
<div className="flex items-center gap-2">
<ShieldCheck className="w-3.5 h-3.5 text-emerald-600" />
<span className="text-xs font-semibold text-ink font-body">
Volatile GPU RAM
</span>
</div>
<p className="text-[11px] text-muted leading-relaxed font-body">
In-browser GPU execution with immediate memory flush upon completion. Zero server storage.
</p>
</div>
<Link
href="/apps"
className="w-full inline-flex items-center justify-between px-3.5 py-2.5 rounded-2xl text-xs font-body font-semibold text-ink bg-paper-2 hover:bg-ink hover:text-paper-hi transition-colors duration-150 group shadow-2xs"
@@ -717,11 +718,11 @@ export function ToolGridSection({
{/* ================= MOBILE FILTER HEADER (< lg) ================= */}
<div className="lg:hidden space-y-3 pb-4 border-b border-rule">
<div className="flex items-center justify-between">
<span className="text-xs font-semibold text-accent uppercase tracking-wider font-body">
Studio Directory
<span className="text-sm font-bold text-ink font-body">
Categories
</span>
<span className="text-xs font-semibold text-muted font-body">
{tools.length} neural models
<span className="text-xs font-medium text-muted font-body">
{tools.length} tools
</span>
</div>
@@ -789,62 +790,80 @@ export function ToolGridSection({
{/* ================= INTEGRATED STUDIO HEADER ================= */}
<div className="space-y-4 border-b border-rule pb-8">
{/* Breadcrumb row & telemetry */}
<div className="flex flex-wrap items-center justify-between gap-3 text-xs font-body">
<div className="flex items-center gap-2 text-muted">
<span>Studio Directory</span>
<span>/</span>
{/* Breadcrumb row */}
<div className="flex items-center gap-2 text-xs font-body text-muted">
<span>Studio Directory</span>
<span>/</span>
{activeCategoryItem ? (
<>
<button
type="button"
onClick={() => handleSelectCategory('all')}
className="hover:text-ink hover:underline cursor-pointer"
>
All Vision Workspaces
</button>
<span>/</span>
<span className="text-accent font-semibold">
{resolveLocalised(activeCategoryItem.category?.name, locale)}
</span>
</>
) : (
<span className="text-accent font-semibold">
{activeCategoryItem
? resolveLocalised(activeCategoryItem.category?.name, locale)
: 'All Vision Workspaces'}
All Vision Workspaces
</span>
</div>
<div className="flex items-center gap-3">
<span className="inline-flex items-center gap-1.5 px-3 py-1 rounded-full bg-paper-hi border border-rule text-[11px] font-semibold text-ink shadow-2xs">
<Sparkles className="w-3.5 h-3.5 text-accent" />
<span>{tools.length} Models Online</span>
</span>
<span className="inline-flex items-center gap-1.5 px-3 py-1 rounded-full bg-paper-hi border border-rule text-[11px] font-semibold text-emerald-600 shadow-2xs">
<ShieldCheck className="w-3.5 h-3.5 text-emerald-600" />
<span>Zero Server Storage</span>
</span>
</div>
)}
</div>
{/* Kinetic Headline */}
<h1 className="text-3xl sm:text-4xl lg:text-5xl font-display font-bold text-ink tracking-tight">
<KineticText>
{activeCategoryItem
? resolveLocalised(activeCategoryItem.category?.name, locale)
: resolveLocalised(title, locale) || 'AI Photo & Vision Tools Studio'}
</KineticText>
</h1>
{activeCategoryItem ? (
/* Focused Category Workspace Header */
<div className="flex flex-col sm:flex-row sm:items-start justify-between gap-4 pt-1">
<div className="flex items-start gap-3.5">
<div className="w-12 h-12 rounded-2xl flex items-center justify-center bg-paper-hi shadow-xs border border-rule text-accent shrink-0 mt-0.5">
{CATEGORY_THEMES[activeCategoryItem.id]?.icon || <Wand2 className="w-5 h-5 text-accent" />}
</div>
<div>
<div className="flex items-center gap-3">
<h1 className="text-2xl sm:text-3xl lg:text-4xl font-display font-bold text-ink tracking-tight">
<KineticText>
{resolveLocalised(activeCategoryItem.category?.name, locale)}
</KineticText>
</h1>
<span className="text-xs font-semibold text-accent bg-accent/10 px-2.5 py-0.5 rounded-full border border-accent/20 font-body">
{activeCategoryItem.tools.length}{' '}
{activeCategoryItem.tools.length === 1 ? 'tool' : 'tools'}
</span>
</div>
<p className="text-sm sm:text-base text-ink-2 font-body max-w-2xl mt-1.5 leading-relaxed">
{CATEGORY_THEMES[activeCategoryItem.id]?.description ||
resolveLocalised(activeCategoryItem.category?.description, locale)}
</p>
</div>
</div>
{/* Subtitle */}
<p className="text-sm sm:text-base text-ink-2 font-body max-w-3xl leading-relaxed">
{activeCategoryItem
? CATEGORY_THEMES[activeCategoryItem.id]?.description ||
resolveLocalised(activeCategoryItem.category?.description, locale)
: resolveLocalised(subtitle, locale) ||
'Client-side neural vision models running directly in volatile GPU memory with zero retention. Test interactive before/after sliders or export in native 4K.'}
</p>
{/* Studio Capability Badges */}
<div className="pt-2 flex flex-wrap items-center gap-2 text-xs font-body text-ink-2">
<span className="inline-flex items-center gap-1.5 px-3 py-1 rounded-full bg-paper-2 border border-rule/70">
<Zap className="w-3.5 h-3.5 text-amber-500" />
<span>Instant in-browser trial</span>
</span>
<span className="inline-flex items-center gap-1.5 px-3 py-1 rounded-full bg-paper-2 border border-rule/70">
<ShieldCheck className="w-3.5 h-3.5 text-emerald-600" />
<span>Ephemeral RAM purge</span>
</span>
<span className="inline-flex items-center gap-1.5 px-3 py-1 rounded-full bg-paper-2 border border-rule/70">
<Smartphone className="w-3.5 h-3.5 text-accent" />
<span>iOS & Mac app handoff</span>
</span>
</div>
<button
type="button"
onClick={() => handleSelectCategory('all')}
className="self-start sm:self-center shrink-0 inline-flex items-center gap-1.5 px-4 py-2 rounded-full text-xs font-body font-semibold text-ink bg-paper-hi border border-rule hover:border-accent hover:text-accent transition-colors shadow-2xs cursor-pointer"
>
<span>Show all {tools.length} tools</span>
<ArrowRight className="w-3.5 h-3.5 text-accent" />
</button>
</div>
) : (
/* Universal Studio Overview Header */
<div>
<h1 className="text-3xl sm:text-4xl lg:text-5xl font-display font-bold text-ink tracking-tight">
<KineticText>
{resolveLocalised(title, locale) || 'AI Photo & Vision Tools Studio'}
</KineticText>
</h1>
<p className="text-sm sm:text-base text-ink-2 font-body max-w-3xl mt-3 leading-relaxed">
{resolveLocalised(subtitle, locale) ||
'Client-side neural vision models running directly in volatile GPU memory with zero retention. Test interactive before/after sliders or export in native 4K.'}
</p>
</div>
)}
</div>
{/* ================= SEARCH RESULTS ACTIVE VIEW ================= */}
@@ -891,41 +910,25 @@ export function ToolGridSection({
</div>
)}
</div>
) : activeCategoryItem ? (
/* ================= SINGLE CATEGORY FOCUSED WORKSPACE ================= */
<div className="space-y-6">
<div className="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-6 sm:gap-7 lg:gap-8">
{activeCategoryItem.tools.map((tool) => (
<ToolCard
key={tool.id}
tool={tool}
locale={locale}
categoryName={resolveLocalised(activeCategoryItem.category?.name, locale)}
/>
))}
</div>
</div>
) : (
/* ================= CATEGORIZED TOOLS GALLERY ================= */
<div className="space-y-12 sm:space-y-16">
{/* Active Category Header Banner if filtered */}
{activeCategoryItem && (
<div className="studio-sheet p-6 sm:p-7 rounded-3xl bg-paper-hi border border-rule shadow-[0_4px_24px_-4px_rgba(0,0,0,0.03)] flex flex-col sm:flex-row sm:items-center justify-between gap-5">
<div className="space-y-2">
<div className="flex items-center gap-2">
<span className="w-2 h-2 rounded-full bg-accent animate-pulse" />
<span className="text-xs font-semibold text-accent font-body">
Active Studio Workspace
</span>
</div>
<h2 className="text-2xl sm:text-3xl font-display font-extrabold text-ink tracking-tight">
{resolveLocalised(activeCategoryItem.category?.name, locale)}
</h2>
<p className="text-xs sm:text-sm text-ink-2 font-body max-w-2xl leading-relaxed">
{CATEGORY_THEMES[activeCategoryItem.id]?.description ||
resolveLocalised(activeCategoryItem.category?.description, locale)}
</p>
</div>
<button
onClick={() => handleSelectCategory('all')}
className="self-start sm:self-center shrink-0 inline-flex items-center gap-1.5 px-4 py-2 rounded-full text-xs font-body font-semibold text-ink bg-paper border border-rule hover:border-accent hover:text-accent transition-colors shadow-2xs cursor-pointer"
>
<span>Show all {tools.length} tools</span>
<ArrowRight className="w-3.5 h-3.5 text-accent" />
</button>
</div>
)}
{/* Displayed Categories */}
{displayedCategories.map((group) => {
{categorizedTools.map((group) => {
const theme = CATEGORY_THEMES[group.id];
const catName = group.category
? resolveLocalised(group.category.name, locale)
@@ -953,7 +956,7 @@ export function ToolGridSection({
</h3>
<span className="text-xs font-semibold text-accent bg-accent/10 px-2.5 py-0.5 rounded-full border border-accent/20 font-body">
{group.tools.length}{' '}
{group.tools.length === 1 ? 'model' : 'models'}
{group.tools.length === 1 ? 'tool' : 'tools'}
</span>
</div>
{catDesc && (
+20 -4
View File
@@ -81,17 +81,22 @@ export function CardBeforeAfterSlider({
);
const handlePointerDown = (e: React.PointerEvent) => {
if (e.button !== 0 && e.pointerType === 'mouse') return;
e.stopPropagation();
isDraggingRef.current = true;
isInteractedRef.current = true;
if (containerRef.current) {
cachedRectRef.current = containerRef.current.getBoundingClientRect();
}
(e.target as HTMLElement).setPointerCapture(e.pointerId);
try {
(e.currentTarget as HTMLElement).setPointerCapture(e.pointerId);
} catch {}
updatePosition(e.clientX);
};
const handlePointerMove = (e: React.PointerEvent) => {
if (!isDraggingRef.current) return;
e.stopPropagation();
if (rafIdRef.current !== null) cancelAnimationFrame(rafIdRef.current);
rafIdRef.current = requestAnimationFrame(() => {
updatePosition(e.clientX);
@@ -99,15 +104,25 @@ export function CardBeforeAfterSlider({
};
const handlePointerUp = (e: React.PointerEvent) => {
if (!isDraggingRef.current) return;
e.stopPropagation();
isDraggingRef.current = false;
cachedRectRef.current = null;
try {
(e.target as HTMLElement).releasePointerCapture(e.pointerId);
(e.currentTarget as HTMLElement).releasePointerCapture(e.pointerId);
} catch {
// Ignore if pointer capture already released
}
};
// On desktop with mouse, clicking anywhere on the card moves the slider.
// On phones / touch screens, touching the card does NOT move the slider,
// allowing completely unobstructed vertical page scrolling!
const handleContainerPointerDown = (e: React.PointerEvent) => {
if (e.pointerType !== 'mouse' || e.button !== 0) return;
handlePointerDown(e);
};
const handleMouseEnter = () => {
isHoveredRef.current = true;
setIsHoveredState(true);
@@ -128,9 +143,10 @@ export function CardBeforeAfterSlider({
return (
<div
ref={containerRef}
onPointerDown={handleContainerPointerDown}
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
className={`relative w-full ${aspectRatio} select-none overflow-hidden rounded-card bg-paper-2 cursor-ew-resize group/slider`}
className={`relative w-full ${aspectRatio} select-none overflow-hidden rounded-card bg-paper-2 cursor-ew-resize group/slider touch-pan-y`}
style={{ touchAction: 'pan-y', ['--split' as any]: '50%' }}
role="region"
aria-label={`${title} comparison slider`}
@@ -174,7 +190,7 @@ export function CardBeforeAfterSlider({
aria-valuenow={50}
tabIndex={0}
style={{ touchAction: 'none' }}
className="absolute top-1/2 -translate-y-1/2 -translate-x-1/2 w-8 h-8 rounded-full bg-paper-hi text-ink border border-rule flex items-center justify-center pointer-events-auto cursor-ew-resize touch-none shadow-sm"
className="absolute top-1/2 -translate-y-1/2 -translate-x-1/2 w-8 h-8 rounded-full bg-paper-hi text-ink border border-rule flex items-center justify-center pointer-events-auto cursor-ew-resize touch-none shadow-sm before:absolute before:-inset-3 before:content-['']"
>
<svg className="w-3.5 h-3.5 text-accent pointer-events-none" fill="none" stroke="currentColor" viewBox="0 0 24 24" aria-hidden="true">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M8 9l-3 3 3 3m8-6l3 3-3 3" />