feat(tool-workspace): add default image cropper, dynamic remaining quota badge, clean studio header, and larger title

This commit is contained in:
2026-11-11 14:41:13 +05:30
parent b5c7cea593
commit 0b00b9d178
5 changed files with 681 additions and 293 deletions
+221 -291
View File
@@ -1,6 +1,6 @@
'use client';
import React, { useState, useRef, useCallback } from 'react';
import React, { useState, useRef, useCallback, useEffect } from 'react';
import Link from 'next/link';
import {
UploadCloud,
@@ -10,20 +10,11 @@ import {
RotateCcw,
Loader2,
AlertCircle,
CheckCircle2,
Layers,
SlidersHorizontal,
ArrowRight,
Maximize2,
Wand2,
RefreshCw,
Image as ImageIcon,
Check,
ChevronRight,
Smartphone,
FolderOpen,
Zap,
ShieldCheck
Crop
} from 'lucide-react';
import {
ToolItem,
@@ -38,7 +29,7 @@ import { MaskCanvasEditor } from './MaskCanvasEditor';
import { ThumbnailsSection } from './ThumbnailsSection';
import { AlternatingFeaturesSection } from './AlternatingFeaturesSection';
import { ProcessingOverlay } from './ProcessingOverlay';
import { KineticText } from '@/components/magicui/kinetic-text';
import { ImageCropper } from './ImageCropper';
import { AnimatedShinyText } from '@/components/magicui/animated-shiny-text';
import { BorderBeam } from '@/components/magicui/border-beam';
@@ -59,7 +50,7 @@ export function DynamicToolWorkspace({
const pageType: ToolPageType = tool.pageType || (
tool.id.includes('lama') || tool.id.includes('eraser') || tool.id.includes('inpaint')
? 'masking'
: tool.id.includes('cartoon') || tool.id.includes('polaroid')
: tool.thumbnails && tool.thumbnails.length > 0
? 'image-thumbnail'
: tool.id.includes('text') || tool.id.includes('prompt')
? 'text-to-image'
@@ -91,6 +82,10 @@ export function DynamicToolWorkspace({
const [hasMaskDrawn, setHasMaskDrawn] = useState(false);
const getMaskBlobRef = useRef<(() => Promise<Blob | null>) | null>(null);
// Cropper State & Export Ref
const getCroppedBlobRef = useRef<(() => Promise<Blob | null>) | null>(null);
const [isCropFull, setIsCropFull] = useState(true);
// Inference Execution State
const [status, setStatus] = useState<'idle' | 'processing' | 'success' | 'error' | 'limit'>('idle');
const [resultUrl, setResultUrl] = useState<string | null>(null);
@@ -100,6 +95,25 @@ export function DynamicToolWorkspace({
const fileInputRef = useRef<HTMLInputElement>(null);
const secondaryFileInputRef = useRef<HTMLInputElement>(null);
// Fetch verified user quota from server dynamically (immune to inspect tool manipulation)
const fetchUserQuota = useCallback(async () => {
try {
const res = await fetch('/api/user-quota', { cache: 'no-store' });
if (res.ok) {
const data = await res.json();
if (typeof data.remainingToday === 'number') {
setRemainingTries(data.remainingToday);
}
}
} catch {
// Keep existing state
}
}, []);
useEffect(() => {
fetchUserQuota();
}, [fetchUserQuota]);
// Examples from JSON
const primaryExample = tool.content?.examples?.[0] || {
before: 'https://images.unsplash.com/photo-1534528741775-53994a69daeb?w=800&auto=format&fit=crop&q=80',
@@ -151,7 +165,7 @@ export function DynamicToolWorkspace({
setSecondaryPreview(URL.createObjectURL(file));
};
const handleLoadSample = (sampleUrl: string, sampleResult?: string) => {
const handleLoadSample = (sampleUrl: string) => {
setPrimaryPreview(sampleUrl);
setPrimaryFile(null);
setResultUrl(null);
@@ -165,6 +179,12 @@ export function DynamicToolWorkspace({
// Execute Request dynamically according to pageType
const handleExecute = async () => {
if (remainingTries <= 0) {
setStatus('limit');
setErrorMessage('You have reached the free operations limit for today. Try again tomorrow or get the mobile app.');
return;
}
setStatus('processing');
setErrorMessage('');
@@ -174,8 +194,23 @@ export function DynamicToolWorkspace({
// 1. Primary Image (for image-based archetypes)
if (pageType !== 'text-to-image') {
const imageParamName = tool.maskingConfig?.imageParamName || tool.twoImagesConfig?.firstImageParam || 'image';
if (primaryFile) {
formData.append(imageParamName, primaryFile);
let fileToSend: Blob | File | null = primaryFile;
// If user cropped the image via ImageCropper
if (getCroppedBlobRef.current) {
try {
const croppedBlob = await getCroppedBlobRef.current();
if (croppedBlob) {
fileToSend = croppedBlob;
}
} catch (e) {
console.error('Failed to export cropped blob, using original:', e);
}
}
if (fileToSend) {
formData.append(imageParamName, fileToSend, 'photo.jpg');
} else if (primaryPreview) {
const res = await fetch(primaryPreview);
const blob = await res.blob();
@@ -226,7 +261,7 @@ export function DynamicToolWorkspace({
formData.append('aspect_ratio', aspectRatio);
}
// 5. Selected Thumbnail / Style Preset (for image-thumbnail or any tool with thumbnails)
// 5. Selected Thumbnail / Style Preset
if (selectedThumbnail) {
formData.append('style', selectedThumbnail.value);
formData.append('variant', selectedThumbnail.value);
@@ -254,7 +289,14 @@ export function DynamicToolWorkspace({
const outputUrl = URL.createObjectURL(blob);
setResultUrl(outputUrl);
setStatus('success');
setRemainingTries((prev) => Math.max(0, prev - 1));
// Update verified remaining count from server response headers or server quota
const remainingHeader = res.headers.get('X-Remaining-Tries');
if (remainingHeader !== null && !isNaN(parseInt(remainingHeader, 10))) {
setRemainingTries(parseInt(remainingHeader, 10));
} else {
fetchUserQuota();
}
} catch {
setStatus('error');
setErrorMessage('Network error during model inference.');
@@ -283,83 +325,54 @@ export function DynamicToolWorkspace({
if (viewMode === 'studio') {
return (
<div className="min-h-screen bg-paper pb-20">
{/* Studio Sticky Header */}
{/* Studio Clean Top Bar (Old duplicate buttons & pills removed) */}
<div className="sticky top-0 z-40 bg-paper-hi/95 backdrop-blur-md border-b border-rule shadow-2xs">
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 h-16 flex items-center justify-between gap-4">
{/* Left: Back to Overview & Tool Title */}
{/* Left: Clean Back to Overview */}
<button
type="button"
onClick={() => setViewMode('landing')}
className="inline-flex items-center gap-2 px-3.5 py-2 rounded-xl text-xs font-sans font-semibold text-slate-700 bg-slate-100 hover:bg-slate-200 transition-colors cursor-pointer"
>
<ArrowLeft className="w-4 h-4" />
<span>Back to Overview</span>
</button>
{/* Right: Direct Download when Result is Ready */}
<div className="flex items-center gap-3">
<button
type="button"
onClick={() => setViewMode('landing')}
className="inline-flex items-center gap-1.5 px-3 py-1.5 rounded-xl text-xs font-body font-semibold text-ink-2 bg-paper-2 hover:bg-paper hover:text-ink transition-colors cursor-pointer"
>
<ArrowLeft className="w-3.5 h-3.5" />
<span>Overview</span>
</button>
<div className="h-4 w-px bg-rule hidden sm:block" />
<div className="flex items-center gap-2">
<span className="font-display font-bold text-ink text-sm sm:text-base">
{toolName}
</span>
<span className="px-2 py-0.5 rounded-full bg-accent/10 border border-accent/20 text-[10px] font-semibold text-accent uppercase tracking-wider font-body hidden md:inline-block">
{pageType} studio
</span>
</div>
</div>
{/* Right: Actions, Tries, Process Button */}
<div className="flex items-center gap-3">
<span className="text-xs text-muted font-body hidden sm:inline-block">
{remainingTries} free tries today
</span>
<button
type="button"
onClick={handleResetStudio}
className="p-2 rounded-xl text-ink-2 hover:bg-paper hover:text-ink transition-colors cursor-pointer"
title="Reset studio"
>
<RotateCcw className="w-4 h-4" />
</button>
{status === 'success' && resultUrl ? (
{status === 'success' && resultUrl && (
<a
href={resultUrl}
download={`${tool.slug}-result.png`}
className="inline-flex items-center gap-1.5 px-4 py-2 rounded-full bg-ink text-paper-hi text-xs font-semibold shadow-xs hover:bg-slate-900 transition-colors cursor-pointer"
className="inline-flex items-center gap-2 px-5 py-2 rounded-full bg-slate-900 text-white text-xs font-semibold shadow-xs hover:bg-slate-800 transition-colors cursor-pointer"
>
<Download className="w-3.5 h-3.5" />
<Download className="w-3.5 h-3.5 text-accent" />
<span>Download Result</span>
</a>
) : (
<button
type="button"
onClick={handleExecute}
disabled={status === 'processing'}
className="inline-flex items-center gap-2 px-5 py-2 rounded-full bg-accent text-white text-xs font-semibold shadow-xs hover:bg-accent-hi transition-colors cursor-pointer disabled:opacity-50"
>
{status === 'processing' ? (
<>
<Loader2 className="w-3.5 h-3.5 animate-spin" />
<span>Processing...</span>
</>
) : (
<>
<Sparkles className="w-3.5 h-3.5" />
<span>Process Photo</span>
</>
)}
</button>
)}
</div>
</div>
</div>
{/* Studio Workspace Canvas */}
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 pt-5 space-y-5">
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 pt-6 space-y-6">
{/* Prominent, Visually Large Tool Heading & Subtitle */}
<div className="space-y-2">
<div className="flex items-center gap-2 text-xs font-sans text-slate-500">
<Link href="/tools" className="hover:text-slate-900 hover:underline">Tools</Link>
<span>/</span>
<span className="text-slate-700 font-medium">{toolName}</span>
</div>
<h1 className="text-3xl sm:text-5xl font-display font-extrabold text-slate-900 tracking-tight">
{toolName}
</h1>
<p className="text-sm sm:text-base text-slate-600 font-sans max-w-3xl leading-relaxed">
{toolSummary}
</p>
</div>
{/* Error Banner */}
{errorMessage && (
<div className="p-3.5 rounded-xl bg-red-500/10 border border-red-500/20 text-red-600 text-xs font-sans flex items-center gap-2">
@@ -369,7 +382,7 @@ export function DynamicToolWorkspace({
)}
{/* Archetype Studio Layout */}
<div className="studio-sheet p-5 sm:p-6 rounded-2xl bg-paper-hi border border-rule shadow-sheet space-y-5">
<div className="studio-sheet p-5 sm:p-6 rounded-3xl bg-paper-hi border border-rule shadow-sheet space-y-6">
{/* POST-EDIT RESULT COMPARISON VIEW (If inference succeeded) */}
{status === 'success' && resultUrl ? (
@@ -405,8 +418,8 @@ export function DynamicToolWorkspace({
/>
</div>
{/* POST-EDIT ACTION BAR: DIRECTLY BELOW THE RESULT SLIDER */}
<div className="pt-6 border-t border-rule space-y-4">
{/* POST-EDIT ACTION BAR */}
<div className="pt-6 border-t border-rule">
<div className="flex flex-col sm:flex-row items-center justify-between gap-4">
<div className="flex items-center gap-2.5 w-full sm:w-auto order-2 sm:order-1">
<button
@@ -441,7 +454,8 @@ export function DynamicToolWorkspace({
) : (
/* PRE-EDIT WORKSPACE (Interactive Editing by Page Type) */
<div className="space-y-6">
{/* 1. MASKING STUDIO (Auto-mask + Custom Mask Brush) */}
{/* 1. MASKING STUDIO (Inpainting & Brush Editor) */}
{pageType === 'masking' && primaryPreview && (
<div className="space-y-4">
<div className="flex items-center justify-between pb-2 border-b border-rule">
@@ -467,41 +481,30 @@ export function DynamicToolWorkspace({
</div>
)}
{/* 2. IMAGE + THUMBNAIL STUDIO */}
{pageType === 'image-thumbnail' && primaryPreview && (
{/* 2. DEFAULT PHOTO CROPPER STUDIO (For image-only and image-thumbnail) */}
{(pageType === 'image-only' || pageType === 'image-thumbnail') && primaryPreview && (
<div className="space-y-4">
<div className="aspect-[4/3] sm:aspect-[16/10] max-h-[520px] w-full rounded-2xl overflow-hidden bg-paper-2 border border-rule relative">
{/* eslint-disable-next-line @next/next/no-img-element */}
<img
src={primaryPreview}
alt="Uploaded preview"
className="w-full h-full object-contain"
<div className="relative">
<ImageCropper
imageUrl={primaryPreview}
onCropChange={(crop, isFull) => {
setIsCropFull(isFull);
}}
onExportReady={(fn) => {
getCroppedBlobRef.current = fn;
}}
disabled={status === 'processing'}
/>
{status === 'processing' && (
<ProcessingOverlay toolName={toolName} />
<div className="absolute inset-0 z-30 rounded-2xl overflow-hidden">
<ProcessingOverlay toolName={toolName} />
</div>
)}
</div>
</div>
)}
{/* 3. IMAGE-ONLY STUDIO */}
{pageType === 'image-only' && primaryPreview && (
<div className="space-y-4">
<div className="aspect-[4/3] sm:aspect-[16/10] max-h-[520px] w-full rounded-2xl overflow-hidden bg-paper-2 border border-rule relative">
{/* eslint-disable-next-line @next/next/no-img-element */}
<img
src={primaryPreview}
alt="Uploaded preview"
className="w-full h-full object-contain"
/>
{status === 'processing' && (
<ProcessingOverlay toolName={toolName} />
)}
</div>
</div>
)}
{/* 4. TEXT-TO-IMAGE STUDIO */}
{/* 3. TEXT-TO-IMAGE STUDIO */}
{pageType === 'text-to-image' && (
<div className="space-y-5">
<label className="block text-xs font-semibold text-ink font-body">
@@ -548,7 +551,7 @@ export function DynamicToolWorkspace({
</div>
)}
{/* 5. TWO-IMAGES STUDIO */}
{/* 4. TWO-IMAGES STUDIO */}
{pageType === 'two-images' && (
<div className="relative">
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
@@ -604,7 +607,7 @@ export function DynamicToolWorkspace({
</div>
)}
{/* In-Studio Style Preset Thumbnails (for image-thumbnail or masking with thumbnails) */}
{/* In-Studio Style Preset Thumbnails (if available) */}
{tool.thumbnails && tool.thumbnails.length > 0 && (
<div className="pt-4 border-t border-rule">
<ThumbnailsSection
@@ -618,42 +621,31 @@ export function DynamicToolWorkspace({
)}
{/* ================================================================= */}
{/* STUDIO MAIN ACTION BAR: CLEARLY VISIBLE PRIMARY & SECONDARY BUTTONS */}
{/* DIRECTLY BELOW THE PHOTO UPLOAD CANVAS (USER MANDATE) */}
{/* STUDIO MAIN ACTION BAR: CLEARLY VISIBLE PRIMARY BUTTON WITH REMAINING COUNT */}
{/* DIRECTLY BELOW THE PHOTO UPLOAD CANVAS */}
{/* ================================================================= */}
<div className="pt-6 border-t border-rule space-y-4">
<div className="pt-6 border-t border-rule">
<div className="flex flex-col sm:flex-row items-center justify-between gap-4">
{/* Left: Secondary actions (Change Photo, Reset, etc.) */}
{/* Left: Reset / Try Another Photo */}
<div className="flex items-center gap-2.5 w-full sm:w-auto order-2 sm:order-1">
{pageType !== 'text-to-image' && (
<button
type="button"
onClick={() => fileInputRef.current?.click()}
className="flex-1 sm:flex-none inline-flex items-center justify-center gap-2 px-5 py-3.5 rounded-2xl bg-paper-2 hover:bg-paper text-ink font-body text-xs sm:text-sm font-semibold border border-rule transition-colors cursor-pointer shadow-2xs"
>
<FolderOpen className="w-4 h-4 text-accent" />
<span>Change Photo</span>
</button>
)}
<button
type="button"
onClick={handleResetStudio}
className="inline-flex items-center justify-center gap-1.5 px-4 py-3.5 rounded-2xl bg-paper-2 hover:bg-red-50 hover:text-red-600 hover:border-red-200 text-ink-2 font-body text-xs sm:text-sm font-medium border border-rule transition-colors cursor-pointer shadow-2xs"
className="inline-flex items-center justify-center gap-2 px-5 py-3.5 rounded-2xl bg-paper-2 hover:bg-paper text-ink font-body text-xs sm:text-sm font-semibold border border-rule transition-colors cursor-pointer shadow-2xs"
>
<RotateCcw className="w-3.5 h-3.5" />
<span>Reset</span>
<RotateCcw className="w-4 h-4 text-slate-500" />
<span>Try Another Photo</span>
</button>
</div>
{/* Right: Massive High-Visibility Main Process Button */}
{/* Right: Massive High-Visibility Main Process Button with Dynamic Server-backed Quota Icon */}
<div className="w-full sm:w-auto order-1 sm:order-2">
<button
type="button"
onClick={handleExecute}
disabled={status === 'processing'}
className="w-full sm:w-auto inline-flex items-center justify-center gap-3 px-8 sm:px-12 py-4 rounded-2xl sm:rounded-full bg-accent hover:bg-accent-hi text-white font-display font-extrabold text-sm sm:text-base shadow-xl shadow-accent/25 hover:shadow-accent/40 hover:scale-[1.02] active:scale-98 transition-all cursor-pointer disabled:opacity-50 disabled:hover:scale-100"
disabled={status === 'processing' || remainingTries <= 0}
className="w-full sm:w-auto inline-flex items-center justify-center gap-3 px-8 sm:px-10 py-4 rounded-2xl sm:rounded-full bg-accent hover:bg-accent-hi text-white font-display font-extrabold text-sm sm:text-base shadow-xl shadow-accent/25 hover:shadow-accent/40 hover:scale-[1.02] active:scale-98 transition-all cursor-pointer disabled:opacity-50 disabled:hover:scale-100"
>
{status === 'processing' ? (
<>
@@ -674,19 +666,17 @@ export function DynamicToolWorkspace({
? `Apply ${resolveLocalised(selectedThumbnail.label, locale)} Look`
: 'Process & Enhance Photo'}
</span>
<ArrowRight className="w-4 h-4" />
{/* Dynamic Icon Badge Showing Remaining Tries */}
<span className="inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full bg-white/20 text-white font-mono text-xs font-bold shadow-2xs backdrop-blur-xs ml-1">
<Zap className="w-3.5 h-3.5 text-amber-300" />
<span>{remainingTries} left</span>
</span>
<ArrowRight className="w-4 h-4 ml-0.5" />
</>
)}
</button>
</div>
</div>
<div className="flex flex-wrap items-center justify-between text-[11px] text-muted font-body px-1 gap-2">
<span className="flex items-center gap-1 text-emerald-600 font-medium">
<CheckCircle2 className="w-3 h-3" />
<span>Volatile GPU memory execution · Zero server storage</span>
</span>
<span className="font-mono">{remainingTries} free daily operations remaining</span>
</div>
</div>
@@ -695,15 +685,6 @@ export function DynamicToolWorkspace({
</div>
{/* Quick Info Row */}
<div className="flex flex-wrap items-center justify-between gap-4 text-xs font-body text-muted px-2">
<div className="flex items-center gap-2 text-emerald-600">
<CheckCircle2 className="w-3.5 h-3.5" />
<span>In-browser volatile GPU RAM execution · Zero server storage</span>
</div>
<span>Unlimited batch & 4K exports available in {homeApp ? resolveLocalised(homeApp.name, locale) : 'the mobile app'}</span>
</div>
</div>
</div>
);
@@ -716,17 +697,17 @@ export function DynamicToolWorkspace({
<div className="min-h-screen bg-paper">
{/* ================= HERO SECTION ================= */}
<section className="relative pt-6 sm:pt-8 pb-10 sm:pb-12 bg-paper border-b border-rule overflow-hidden">
<section className="relative pt-6 sm:pt-10 pb-12 sm:pb-16 bg-paper border-b border-rule overflow-hidden">
{/* Ambient Radial Spotlight */}
<div
className="pointer-events-none absolute top-0 left-1/2 -translate-x-1/2 w-[800px] h-[350px] [background:radial-gradient(ellipse_at_top,color-mix(in_oklab,var(--color-accent)_10%,transparent)_0%,transparent_70%)]"
className="pointer-events-none absolute top-0 left-1/2 -translate-x-1/2 w-[900px] h-[400px] [background:radial-gradient(ellipse_at_top,color-mix(in_oklab,var(--color-accent)_12%,transparent)_0%,transparent_70%)]"
aria-hidden="true"
/>
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 relative z-10">
{/* Breadcrumb row */}
<div className="flex items-center gap-2 text-xs font-sans text-slate-500 mb-4 tracking-wide">
<div className="flex items-center gap-2 text-xs font-sans text-slate-500 mb-5 tracking-wide">
<Link href="/" className="hover:text-slate-900 hover:underline">Home</Link>
<span>/</span>
<Link href="/tools" className="hover:text-slate-900 hover:underline">Tools</Link>
@@ -734,12 +715,12 @@ export function DynamicToolWorkspace({
<span className="text-accent font-semibold">{toolName}</span>
</div>
{/* Header Title & Summary (Pills removed, generous typography breathing room) */}
<div className="max-w-5xl mb-8 sm:mb-10 space-y-4">
<h1 className="text-3xl sm:text-5xl font-display font-extrabold text-ink tracking-tight leading-tight">
{/* Header Title & Summary (Larger, visually striking typography) */}
<div className="max-w-5xl mb-8 sm:mb-12 space-y-4 sm:space-y-5">
<h1 className="text-4xl sm:text-6xl lg:text-7xl font-display font-extrabold text-slate-900 tracking-tight leading-[1.08]">
<AnimatedShinyText>{toolName}</AnimatedShinyText>
</h1>
<p className="text-base sm:text-lg text-ink-2 font-sans max-w-4xl leading-relaxed">
<p className="text-base sm:text-xl text-slate-600 font-sans max-w-4xl leading-relaxed">
{toolSummary}
</p>
</div>
@@ -753,9 +734,8 @@ export function DynamicToolWorkspace({
<div className="border-b border-rule pb-3.5 mb-6 flex items-center justify-between">
<span className="text-sm font-bold font-sans text-slate-900">
{pageType === 'text-to-image' ? 'Text prompt studio' : 'Interactive tool studio'}
{pageType === 'text-to-image' ? 'Generate AI Image' : 'Select Photo to Edit'}
</span>
<span className="text-xs text-slate-500 font-sans">Zero server retention</span>
</div>
{/* Dynamic Upload Input by Type */}
@@ -780,10 +760,10 @@ export function DynamicToolWorkspace({
key={t.id}
type="button"
onClick={() => setSelectedThumbnail(t)}
className={`shrink-0 flex items-center gap-2 px-3.5 py-2 rounded-xl border text-xs sm:text-sm font-sans font-semibold transition-all cursor-pointer ${
className={`shrink-0 flex items-center gap-2 px-3 py-1.5 rounded-xl text-xs font-sans transition-all cursor-pointer ${
isSelected
? 'bg-accent/10 border-accent text-accent shadow-xs'
: 'bg-paper border-rule text-slate-800 hover:border-rule-2'
? 'bg-slate-900 text-white shadow-xs font-semibold'
: 'bg-slate-100 text-slate-700 hover:bg-slate-200'
}`}
>
{(t.thumbnail || t.preview) && (
@@ -798,117 +778,110 @@ export function DynamicToolWorkspace({
</div>
)}
{/* Type 1, 2, 3: Spacious, Prominently Sized Drag & Drop Dropzone */}
{pageType !== 'text-to-image' && pageType !== 'two-images' && (
{/* 1. Standard Single Upload Dropzone */}
{pageType !== 'two-images' && pageType !== 'text-to-image' && (
<div className="space-y-5">
<input
ref={fileInputRef}
type="file"
accept="image/jpeg,image/png,image/webp"
className="hidden"
onChange={(e) => {
if (e.target.files?.[0]) handlePrimaryFileSelect(e.target.files[0]);
}}
/>
{/* Prominent High-Visibility Drag & Drop Zone */}
<div
onClick={() => fileInputRef.current?.click()}
onDragOver={(e) => e.preventDefault()}
onDrop={(e) => {
e.preventDefault();
if (e.dataTransfer.files?.[0]) handlePrimaryFileSelect(e.dataTransfer.files[0]);
}}
onClick={() => fileInputRef.current?.click()}
className="min-h-[280px] sm:min-h-[320px] flex flex-col items-center justify-center border-2 border-dashed border-rule hover:border-accent rounded-3xl p-8 sm:p-12 text-center bg-paper/60 hover:bg-accent/5 transition-all cursor-pointer group"
className="w-full min-h-[320px] p-8 sm:p-12 rounded-2xl border-2 border-dashed border-accent/40 hover:border-accent bg-accent/5 hover:bg-accent/10 transition-all cursor-pointer flex flex-col items-center justify-center text-center space-y-4 group shadow-inner"
>
<input
ref={fileInputRef}
type="file"
accept="image/jpeg,image/png,image/webp"
className="hidden"
onChange={(e) => {
if (e.target.files?.[0]) handlePrimaryFileSelect(e.target.files[0]);
}}
/>
<div className="w-16 h-16 sm:w-20 sm:h-20 rounded-3xl bg-paper-hi border border-rule flex items-center justify-center text-accent mx-auto mb-4 group-hover:scale-105 group-hover:border-accent transition-transform shadow-xs">
<div className="w-16 h-16 sm:w-20 sm:h-20 rounded-2xl bg-white shadow-md flex items-center justify-center group-hover:scale-110 transition-transform">
<UploadCloud className="w-8 h-8 sm:w-10 sm:h-10 text-accent" />
</div>
<h4 className="text-lg sm:text-xl font-display font-bold text-ink tracking-tight">
Drag and drop your image here
</h4>
<p className="text-xs sm:text-sm text-slate-500 font-sans mt-2 max-w-sm mx-auto leading-relaxed">
Supports high-resolution JPG, PNG, and WebP up to 12MB. Zero server retention.
</p>
</div>
{/* PROMINENT ACTION BUTTONS DIRECTLY BELOW PHOTO UPLOAD */}
<div className="grid grid-cols-1 sm:grid-cols-2 gap-3.5 pt-1">
<div className="space-y-1">
<span className="text-base sm:text-lg font-bold text-slate-900 block font-sans">
Click to upload or drag photo here
</span>
<p className="text-xs sm:text-sm text-slate-500 font-sans">
Supports JPEG, PNG, and WebP (up to {tool.tryIt?.limits?.maxMB || 12}MB)
</p>
</div>
<button
type="button"
onClick={() => fileInputRef.current?.click()}
className="w-full inline-flex items-center justify-center gap-2.5 px-6 py-4 rounded-2xl bg-accent hover:bg-accent-hi text-white font-display font-bold text-sm shadow-md hover:shadow-lg hover:scale-[1.01] active:scale-98 transition-all cursor-pointer group"
onClick={(e) => {
e.stopPropagation();
fileInputRef.current?.click();
}}
className="w-full sm:w-auto px-8 py-3.5 rounded-xl bg-slate-900 hover:bg-slate-800 text-white font-sans font-semibold text-xs sm:text-sm shadow-md transition-colors"
>
<FolderOpen className="w-4 h-4 text-white group-hover:scale-110 transition-transform" />
<span>Select Photo to Upload</span>
Select from Device
</button>
</div>
{samplePresets.length > 0 && (
<button
type="button"
onClick={() => handleLoadSample(samplePresets[0].url, samplePresets[0].resultUrl)}
className="w-full inline-flex items-center justify-center gap-2.5 px-6 py-4 rounded-2xl bg-paper-hi hover:bg-paper-2 border border-rule hover:border-accent text-slate-800 font-sans text-sm font-semibold shadow-2xs hover:shadow-xs active:scale-98 transition-all cursor-pointer group"
>
<Sparkles className="w-4 h-4 text-accent group-hover:rotate-12 transition-transform" />
<span>Try Demo Portrait</span>
</button>
)}
{/* Sample Presets */}
<div className="pt-2 flex items-center justify-between text-xs text-slate-500 font-sans">
<span>No photo ready?</span>
<button
type="button"
onClick={() => handleLoadSample(primaryExample.before)}
className="text-accent font-semibold hover:underline cursor-pointer"
>
Try with sample photo →
</button>
</div>
</div>
)}
{/* Type 5: Two-Images Dual Upload Dropzones */}
{/* 2. Two-Images Archetype Upload */}
{pageType === 'two-images' && (
<div className="space-y-5">
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4">
{/* Box 1: Primary Image */}
{/* Image 1 Dropzone */}
<div
onClick={() => fileInputRef.current?.click()}
className="min-h-[220px] flex flex-col items-center justify-center border-2 border-dashed border-rule hover:border-accent rounded-2xl p-6 text-center bg-paper/60 hover:bg-accent/5 transition-all cursor-pointer group"
className="p-5 rounded-2xl border-2 border-dashed border-rule hover:border-accent bg-paper hover:bg-accent/5 transition-all cursor-pointer flex flex-col items-center justify-center text-center space-y-2 min-h-[160px]"
>
<input
ref={fileInputRef}
type="file"
accept="image/jpeg,image/png,image/webp"
accept="image/*"
className="hidden"
onChange={(e) => {
if (e.target.files?.[0]) handlePrimaryFileSelect(e.target.files[0]);
}}
/>
<div className="w-14 h-14 rounded-2xl bg-paper-hi border border-rule flex items-center justify-center text-accent mx-auto mb-3 group-hover:scale-105 transition-transform shadow-xs">
<UploadCloud className="w-7 h-7" />
</div>
<h5 className="text-sm font-display font-bold text-ink">
{resolveLocalised(tool.twoImagesConfig?.firstImageLabel, locale) || '1. Primary Photo'}
</h5>
<p className="text-xs text-slate-500 font-sans mt-1">
{primaryFile ? primaryFile.name : 'Target face or subject'}
</p>
<UploadCloud className="w-6 h-6 text-accent" />
<span className="text-xs font-bold text-ink font-body">
{resolveLocalised(tool.twoImagesConfig?.firstImageLabel, locale) || '1. Source Face'}
</span>
<span className="text-[10px] text-muted font-body">Click to choose</span>
</div>
{/* Box 2: Reference Image */}
{/* Image 2 Dropzone */}
<div
onClick={() => secondaryFileInputRef.current?.click()}
className="min-h-[220px] flex flex-col items-center justify-center border-2 border-dashed border-rule hover:border-accent rounded-2xl p-6 text-center bg-paper/60 hover:bg-accent/5 transition-all cursor-pointer group"
className="p-5 rounded-2xl border-2 border-dashed border-rule hover:border-accent bg-paper hover:bg-accent/5 transition-all cursor-pointer flex flex-col items-center justify-center text-center space-y-2 min-h-[160px]"
>
<input
ref={secondaryFileInputRef}
type="file"
accept="image/jpeg,image/png,image/webp"
accept="image/*"
className="hidden"
onChange={(e) => {
if (e.target.files?.[0]) handleSecondaryFileSelect(e.target.files[0]);
}}
/>
<div className="w-14 h-14 rounded-2xl bg-paper-hi border border-rule flex items-center justify-center text-accent mx-auto mb-3 group-hover:scale-105 transition-transform shadow-xs">
<ImageIcon className="w-7 h-7" />
</div>
<h5 className="text-sm font-display font-bold text-ink">
{resolveLocalised(tool.twoImagesConfig?.secondImageLabel, locale) || '2. Reference Photo'}
</h5>
<p className="text-xs text-slate-500 font-sans mt-1">
{secondaryFile ? secondaryFile.name : 'Source identity to fuse'}
</p>
<UploadCloud className="w-6 h-6 text-accent" />
<span className="text-xs font-bold text-ink font-body">
{resolveLocalised(tool.twoImagesConfig?.secondImageLabel, locale) || '2. Target Body/Photo'}
</span>
<span className="text-[10px] text-muted font-body">Click to choose</span>
</div>
</div>
@@ -922,13 +895,13 @@ export function DynamicToolWorkspace({
}}
className="w-full py-4 rounded-2xl bg-accent hover:bg-accent-hi text-white font-display font-bold text-sm shadow-md hover:shadow-lg transition-all cursor-pointer flex items-center justify-center gap-2.5"
>
<Sparkles className="w-4 h-4 text-white" />
<span>Open in Dual-Image Studio</span>
<Sparkles className="w-4 h-4 text-amber-300" />
<span>Open Fusion Studio</span>
</button>
</div>
)}
{/* Type 4: Text-to-image Landing Input */}
{/* 3. Text-to-Image Archetype Input */}
{pageType === 'text-to-image' && (
<div className="space-y-4">
<textarea
@@ -937,50 +910,26 @@ export function DynamicToolWorkspace({
onChange={(e) => setPromptText(e.target.value)}
placeholder={
resolveLocalised(tool.textToImageConfig?.placeholder, locale) ||
'Describe what you want to create (e.g. A solitary astronaut standing on crystal sands under a violet nebula, cinematic rim lighting, 8k resolution)...'
'Describe what you want to create in detail...'
}
className="w-full p-4 rounded-2xl border border-rule bg-paper text-ink text-sm font-body placeholder:text-muted focus:outline-none focus:border-accent focus:ring-2 focus:ring-accent/20"
/>
{/* Quick Prompt Ideas */}
<div className="space-y-1.5">
<span className="text-[11px] font-semibold text-muted font-body">Quick prompt inspiration:</span>
<div className="flex flex-wrap items-center gap-1.5">
{[
'Cinematic 35mm portrait with golden hour rim light',
'Makoto Shinkai anime cityscape under starry skies',
'3D Disney character with luminous amber eyes',
'Hyperrealistic wildlife in lush emerald rain forest'
].map((samplePrompt) => (
{/* Sample Prompts */}
{tool.textToImageConfig?.samplePrompts && (
<div className="flex flex-wrap gap-1.5 pt-1">
{tool.textToImageConfig.samplePrompts.slice(0, 3).map((sp, idx) => (
<button
key={samplePrompt}
key={idx}
type="button"
onClick={() => setPromptText(samplePrompt)}
className="px-2.5 py-1 rounded-xl bg-paper-2 hover:bg-paper text-ink-2 hover:text-ink text-[11px] font-body border border-rule transition-colors cursor-pointer text-left truncate max-w-full"
onClick={() => setPromptText(resolveLocalised(sp, locale))}
className="px-2.5 py-1 rounded-lg bg-paper-2 hover:bg-paper border border-rule text-[11px] text-muted hover:text-ink font-body transition-colors cursor-pointer text-left line-clamp-1"
>
+ {samplePrompt}
&ldquo;{resolveLocalised(sp, locale)}&rdquo;
</button>
))}
</div>
</div>
<div className="flex items-center gap-2 pt-1">
<span className="text-xs text-muted font-body">Aspect:</span>
{['1:1', '16:9', '9:16', '4:3'].map((ratio) => (
<button
key={ratio}
type="button"
onClick={() => setAspectRatio(ratio)}
className={`px-3 py-1.5 rounded-xl text-xs font-body font-semibold transition-colors cursor-pointer ${
aspectRatio === ratio
? 'bg-ink text-paper-hi shadow-xs'
: 'bg-paper-2 text-ink-2 hover:bg-paper'
}`}
>
{ratio}
</button>
))}
</div>
)}
<button
type="button"
@@ -992,26 +941,11 @@ export function DynamicToolWorkspace({
}
}
}}
className="w-full py-4 rounded-2xl bg-accent hover:bg-accent-hi text-white text-sm font-display font-bold shadow-md hover:shadow-lg transition-all cursor-pointer flex items-center justify-center gap-2 group"
disabled={!promptText.trim()}
className="w-full py-4 rounded-2xl bg-accent hover:bg-accent-hi disabled:opacity-50 text-white font-display font-bold text-sm shadow-md hover:shadow-lg transition-all cursor-pointer flex items-center justify-center gap-2.5"
>
<Sparkles className="w-4 h-4 text-amber-300 group-hover:rotate-12 transition-transform" />
<span>Open in AI Generation Studio</span>
<ArrowRight className="w-4 h-4 text-white" />
</button>
</div>
)}
{/* Sample Presets to Try Instantly with 1 Click */}
{samplePresets.length > 0 && pageType !== 'text-to-image' && (
<div className="pt-2 border-t border-rule/60 flex items-center justify-between text-xs font-body">
<span className="text-muted">No photo handy?</span>
<button
type="button"
onClick={() => handleLoadSample(samplePresets[0].url, samplePresets[0].resultUrl)}
className="text-accent font-semibold hover:underline inline-flex items-center gap-1 cursor-pointer"
>
<span>Try sample portrait</span>
<ChevronRight className="w-3.5 h-3.5" />
<Sparkles className="w-4 h-4 text-amber-300" />
<span>Open Creation Studio</span>
</button>
</div>
)}
@@ -1031,13 +965,11 @@ export function DynamicToolWorkspace({
beforeUrl={primaryExample.before}
afterUrl={primaryExample.after}
title={toolName}
slug={tool.slug}
aspectRatio="aspect-[4/3]"
aspectRatio="aspect-auto h-full"
beforeLabel="ORIGINAL"
afterLabel="ENHANCED"
/>
</div>
<div className="mt-4 text-xs text-slate-500 font-sans text-center leading-relaxed">
Full 4K batch processing available in {homeApp ? resolveLocalised(homeApp.name, locale) : 'the mobile app'}.
</div>
</div>
</div>
@@ -1064,8 +996,7 @@ export function DynamicToolWorkspace({
}
}}
locale={locale}
title="Explore Visual Styles & Presets"
subtitle="Click any preset thumbnail to select your effect before or during editing."
title={resolveLocalised(tool.name, locale)}
/>
)}
@@ -1163,7 +1094,6 @@ export function DynamicToolWorkspace({
href="/apps"
className="shrink-0 inline-flex items-center gap-2 px-5 py-2.5 rounded-full bg-slate-900 hover:bg-slate-800 text-white text-xs font-semibold shadow-md transition-colors"
>
<Smartphone className="w-4 h-4 text-accent" />
<span>Explore Mobile Apps Suite</span>
</Link>
</div>