fix: align male and female effect IDs with thumbnails, add gender filter tabs and strip request prefixes

This commit is contained in:
2026-11-12 13:50:06 +05:30
parent 5445a8cbee
commit 473b269080
13 changed files with 1339 additions and 720 deletions
@@ -303,6 +303,12 @@ export function DynamicToolWorkspace({
formData.append('effectId', presetVal);
formData.append('colorId', presetVal);
formData.append('effect_id', presetVal);
if ((selectedThumbnail as any).gender) {
formData.append('gender', (selectedThumbnail as any).gender);
}
if ((selectedThumbnail as any).category) {
formData.append('category', (selectedThumbnail as any).category);
}
}
const res = await fetch(`/api/try/${tool.id}`, {
+150 -11
View File
@@ -1,8 +1,8 @@
'use client';
import React from 'react';
import React, { useState, useMemo } from 'react';
import { ThumbnailItem, resolveLocalised } from '@/types';
import { Check, Sparkles } from 'lucide-react';
import { Check, Sparkles, User, Users } from 'lucide-react';
interface ThumbnailsSectionProps {
thumbnails: ThumbnailItem[];
@@ -15,6 +15,18 @@ interface ThumbnailsSectionProps {
className?: string;
}
function getThumbnailGender(item: ThumbnailItem): 'female' | 'male' | 'unisex' {
if (item.gender) return item.gender.toLowerCase() as any;
if (item.category && (item.category.toLowerCase() === 'female' || item.category.toLowerCase() === 'women')) return 'female';
if (item.category && (item.category.toLowerCase() === 'male' || item.category.toLowerCase() === 'men')) return 'male';
const id = item.id.toLowerCase();
if (id.includes('female') || id.startsWith('gw') || id.includes('_f_') || (item.badge && item.badge.toLowerCase().includes('female'))) return 'female';
if (id.includes('male') || id.startsWith('gm') || id.includes('_m_') || (item.badge && item.badge.toLowerCase().includes('male'))) return 'male';
if (/^f\d+$/i.test(item.id)) return 'female';
if (/^m\d+$/i.test(item.id)) return 'male';
return 'unisex';
}
export function ThumbnailsSection({
thumbnails,
selectedId,
@@ -25,24 +37,93 @@ export function ThumbnailsSection({
variant = 'grid',
className = '',
}: ThumbnailsSectionProps) {
const [activeGender, setActiveGender] = useState<'all' | 'female' | 'male'>('all');
const { hasGenderOptions, femaleCount, maleCount, filteredThumbnails } = useMemo(() => {
let female = 0;
let male = 0;
thumbnails.forEach((t) => {
const g = getThumbnailGender(t);
if (g === 'female') female++;
if (g === 'male') male++;
});
const hasGender = female > 0 && male > 0;
const filtered = thumbnails.filter((t) => {
if (activeGender === 'all') return true;
const g = getThumbnailGender(t);
if (activeGender === 'female') return g === 'female' || g === 'unisex';
if (activeGender === 'male') return g === 'male' || g === 'unisex';
return true;
});
return {
hasGenderOptions: hasGender,
femaleCount: female,
maleCount: male,
filteredThumbnails: filtered,
};
}, [thumbnails, activeGender]);
if (!thumbnails || thumbnails.length === 0) return null;
// 1. Compact Bar (Ideal for inside the Studio Editor)
if (variant === 'compact-bar') {
return (
<div className={`space-y-2.5 ${className}`}>
<div className="flex items-center justify-between text-xs font-body">
<div className={`space-y-3 ${className}`}>
<div className="flex flex-wrap items-center justify-between gap-2 text-xs font-body">
<span className="font-semibold text-ink flex items-center gap-1.5">
<Sparkles className="w-3.5 h-3.5 text-accent" />
<span>Select Style Preset</span>
</span>
<span className="text-muted text-[11px]">{thumbnails.length} presets</span>
<div className="flex items-center gap-2">
{hasGenderOptions && (
<div className="flex items-center gap-1 p-0.5 rounded-lg bg-paper-2 border border-rule text-[11px] font-sans">
<button
type="button"
onClick={() => setActiveGender('all')}
className={`px-2 py-0.5 rounded-md transition-colors cursor-pointer ${
activeGender === 'all'
? 'bg-ink text-white font-semibold'
: 'text-ink-2 hover:text-ink'
}`}
>
All ({thumbnails.length})
</button>
<button
type="button"
onClick={() => setActiveGender('female')}
className={`px-2 py-0.5 rounded-md transition-colors cursor-pointer ${
activeGender === 'female'
? 'bg-ink text-white font-semibold'
: 'text-ink-2 hover:text-ink'
}`}
>
Female ({femaleCount})
</button>
<button
type="button"
onClick={() => setActiveGender('male')}
className={`px-2 py-0.5 rounded-md transition-colors cursor-pointer ${
activeGender === 'male'
? 'bg-ink text-white font-semibold'
: 'text-ink-2 hover:text-ink'
}`}
>
Male ({maleCount})
</button>
</div>
)}
<span className="text-muted text-[11px]">{filteredThumbnails.length} presets</span>
</div>
</div>
<div className="flex items-center gap-3 overflow-x-auto no-scrollbar py-1">
{thumbnails.map((item) => {
{filteredThumbnails.map((item) => {
const isSelected = selectedId === item.id;
const label = resolveLocalised(item.label, locale);
const gender = getThumbnailGender(item);
const badgeText = item.badge || (gender === 'female' ? 'Female' : gender === 'male' ? 'Male' : undefined);
return (
<button
@@ -62,6 +143,17 @@ export function ThumbnailsSection({
alt={label}
className="w-full h-full object-cover transition-transform duration-300 group-hover:scale-105"
/>
{badgeText && (
<span className={`absolute bottom-1 left-1 px-1.5 py-0.2 rounded text-[8px] font-bold tracking-tight shadow-xs ${
gender === 'female'
? 'bg-pink-600 text-white'
: gender === 'male'
? 'bg-sky-600 text-white'
: 'bg-ink/80 text-white'
}`}>
{badgeText}
</span>
)}
{isSelected && (
<div className="absolute inset-0 bg-accent/25 flex items-center justify-center">
<div className="w-5 h-5 rounded-full bg-accent text-white flex items-center justify-center shadow-xs">
@@ -86,7 +178,7 @@ export function ThumbnailsSection({
<section className={`py-12 sm:py-16 border-t border-rule bg-paper ${className}`}>
<div className="max-w-6xl mx-auto px-4 sm:px-6 lg:px-8 space-y-8">
{/* Header */}
<div className="text-center max-w-2xl mx-auto space-y-2">
<div className="text-center max-w-2xl mx-auto space-y-3">
<div className="inline-flex items-center gap-2 px-3 py-1 rounded-full bg-accent/10 border border-accent/20 text-accent text-xs font-semibold font-body">
<Sparkles className="w-3.5 h-3.5" />
<span>Preset Gallery</span>
@@ -97,14 +189,55 @@ export function ThumbnailsSection({
<p className="text-xs sm:text-sm text-ink-2 font-body leading-relaxed">
{subtitle}
</p>
{/* Gender Filter Pills (if applicable) */}
{hasGenderOptions && (
<div className="inline-flex items-center gap-1.5 p-1 rounded-xl bg-paper-hi border border-rule shadow-xs text-xs font-sans mt-2">
<button
type="button"
onClick={() => setActiveGender('all')}
className={`px-3.5 py-1.5 rounded-lg transition-all cursor-pointer font-medium ${
activeGender === 'all'
? 'bg-ink text-white font-semibold shadow-xs'
: 'text-ink-2 hover:text-ink'
}`}
>
All Presets ({thumbnails.length})
</button>
<button
type="button"
onClick={() => setActiveGender('female')}
className={`px-3.5 py-1.5 rounded-lg transition-all cursor-pointer font-medium ${
activeGender === 'female'
? 'bg-ink text-white font-semibold shadow-xs'
: 'text-ink-2 hover:text-ink'
}`}
>
Female Styles ({femaleCount})
</button>
<button
type="button"
onClick={() => setActiveGender('male')}
className={`px-3.5 py-1.5 rounded-lg transition-all cursor-pointer font-medium ${
activeGender === 'male'
? 'bg-ink text-white font-semibold shadow-xs'
: 'text-ink-2 hover:text-ink'
}`}
>
Male Styles ({maleCount})
</button>
</div>
)}
</div>
{/* Presets Grid */}
<div className="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 gap-4 sm:gap-5">
{thumbnails.map((item) => {
{filteredThumbnails.map((item) => {
const isSelected = selectedId === item.id;
const label = resolveLocalised(item.label, locale);
const desc = item.description ? resolveLocalised(item.description, locale) : '';
const gender = getThumbnailGender(item);
const badgeText = item.badge || (gender === 'female' ? 'Female' : gender === 'male' ? 'Male' : undefined);
return (
<button
@@ -125,9 +258,15 @@ export function ThumbnailsSection({
alt={label}
className="w-full h-full object-cover transition-transform duration-500 group-hover:scale-105"
/>
{item.badge && (
<span className="absolute top-2 left-2 px-2 py-0.5 rounded-full bg-ink/80 backdrop-blur-md text-[9px] font-bold text-paper-hi uppercase tracking-wider">
{item.badge}
{badgeText && (
<span className={`absolute top-2 left-2 px-2 py-0.5 rounded-full text-[9px] font-bold uppercase tracking-wider shadow-xs ${
gender === 'female'
? 'bg-pink-600 text-white'
: gender === 'male'
? 'bg-sky-600 text-white'
: 'bg-ink/80 text-white'
}`}>
{badgeText}
</span>
)}
{isSelected && (