50+ open-source generative AI apps you can clone, deploy, and monetize — image generators, video tools, virtual try-ons, AI SaaS templates, and platform integrations. One-click Vercel deploy on every template.
JavaScript ai-appsai-image-generatorai-saasai-toolsai-video-generatorawesomeawesome-listgenerative-aigenerative-ai-appsimage-generationnextjsnextjs-boilerplateopen-sourceopen-source-aisaas-boilerplatesaas-templateseedance2text-to-imagetext-to-videovideo-generation
"use client";
import { useState, useEffect } from "react";
import { useSession, signIn } from "next-auth/react";
import Link from "next/link";
import {
FaDownload, FaSpinner, FaGoogle, FaImages, FaEye, FaCut, FaPlus, FaTrashAlt
} from "react-icons/fa";
export default function GalleryPage() {
const { data: session, status } = useSession();
const [creations, setCreations] = useState([]);
const [loading, setLoading] = useState(true);
// Modal details view state
const [selectedCreation, setSelectedCreation] = useState(null);
const [deletingId, setDeletingId] = useState(null);
useEffect(() => {
if (session?.user) {
fetchCompletedCreations();
} else if (status !== "loading") {
setLoading(false);
}
}, [session, status]);
const fetchCompletedCreations = async () => {
setLoading(true);
try {
const res = await fetch("/api/creations");
if (res.ok) {
const data = await res.json();
// Only display successfully completed entries
const completed = data.filter(c => c.status === "completed");
setCreations(completed);
}
} catch (e) {
console.error(e);
} finally {
setLoading(false);
}
};
const handleDownload = async (creation) => {
if (!creation.resultImage) return;
try {
const response = await fetch(creation.resultImage);
const blob = await response.blob();
const blobUrl = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = blobUrl;
a.download = `hairstyle-${creation.id}.png`;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(blobUrl);
} catch (e) {
window.open(creation.resultImage, "_blank");
}
};
const handleDelete = async (id) => {
if (!confirm("Are you sure you want to delete this hairstyle simulation? This action cannot be undone.")) return;
setDeletingId(id);
try {
const res = await fetch(`/api/creations?id=${id}`, { method: "DELETE" });
if (res.ok) {
setCreations(p => p.filter(t => t.id !== id));
if (selectedCreation?.id === id) setSelectedCreation(null);
}
} catch (e) {
console.error(e);
} finally {
setDeletingId(null);
}
};
if (status === "loading" || (loading && creations.length === 0)) {
return (
<div className="flex-1 flex flex-col items-center justify-center bg-zinc-950 text-zinc-300">
<FaSpinner className="animate-spin text-3xl text-violet-400 mb-4" />
<p className="text-sm font-medium">Loading showroom gallery...</p>
</div>
);
}
// Logged out state
if (!session?.user) {
return (
<div className="flex-1 flex items-center justify-center bg-zinc-955 px-4 py-12">
<div className="max-w-md w-full bg-zinc-900 border border-zinc-800 rounded-2xl p-8 text-center shadow-xl">
<div className="h-14 w-14 rounded-2xl bg-violet-600/10 border border-violet-500/30 text-violet-400 flex items-center justify-center mx-auto mb-6 shadow-inner animate-pulse">
<FaImages className="text-2xl" />
</div>
<h1 className="text-2xl font-bold font-heading text-white tracking-tight mb-2">Showroom Gallery</h1>
<p className="text-sm text-zinc-400 leading-relaxed mb-8">
Please sign in to access your HD gallery, view detail comparisons, and download simulated haircuts.
</p>
<button
onClick={() => signIn("google")}
className="w-full flex items-center justify-center gap-2.5 px-5 py-3.5 rounded-xl text-sm font-extrabold text-white bg-gradient-to-r from-violet-600 to-fuchsia-600 hover:from-violet-500 hover:to-fuchsia-500 shadow-lg shadow-violet-500/10 active:scale-[0.98] transition-all cursor-pointer"
>
<FaGoogle className="text-xs" />
<span>Sign in with Google</span>
</button>
</div>
</div>
);
}
return (
<div className="flex-1 overflow-y-auto bg-zinc-955 text-zinc-200 py-8 px-4 sm:px-6 lg:px-8 font-sans">
<div className="max-w-6xl mx-auto">
{/* Header Section */}
<div className="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 mb-8">
<div>
<h1 className="text-2xl font-black font-heading text-white tracking-tight">Showroom Gallery</h1>
<p className="text-xs sm:text-sm text-zinc-400 mt-1.5 font-medium font-sans">Browse your completed high-resolution AI hairstyles</p>
</div>
<Link
href="/"
className="inline-flex items-center justify-center gap-2 px-4.5 py-2.5 bg-gradient-to-r from-violet-600 to-fuchsia-600 hover:from-violet-500 hover:to-fuchsia-500 text-white text-xs font-extrabold rounded-lg shadow-lg shadow-violet-500/5 transition-all w-fit cursor-pointer hover:scale-[1.02] active:scale-[0.98]"
>
<FaPlus className="text-[10px]" /> Studio Workspace
</Link>
</div>
{/* Empty State */}
{creations.length === 0 ? (
<div className="bg-zinc-900 border border-zinc-800 rounded-2xl p-12 text-center shadow-lg max-w-xl mx-auto my-12">
<div className="h-16 w-16 bg-zinc-950 text-zinc-400 border border-zinc-800 rounded-2xl flex items-center justify-center mx-auto mb-6 shadow-inner">
<FaImages className="text-3xl text-zinc-300" />
</div>
<h2 className="text-lg font-bold text-zinc-200 mb-2">No completed hairstyles yet</h2>
<p className="text-sm text-zinc-400 leading-relaxed max-w-sm mx-auto mb-8 font-medium">
You don't have any successfully finished style designs in your showroom yet. Trigger a style makeover in the studio!
</p>
<Link
href="/"
className="inline-flex items-center justify-center gap-2 px-5 py-3.5 bg-gradient-to-r from-violet-600 to-fuchsia-600 hover:from-violet-500 hover:to-fuchsia-500 text-white text-sm font-extrabold rounded-lg shadow-lg shadow-violet-500/10 cursor-pointer hover:scale-[1.02] active:scale-[0.98]"
>
<FaPlus className="text-xs" /> Design New Style
</Link>
</div>
) : (
/* Gallery Grid */
<div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-6">
{creations.map((creation) => (
<div
key={creation.id}
onClick={() => setSelectedCreation(creation)}
className="bg-zinc-900 border border-zinc-800 rounded-2xl overflow-hidden shadow-lg hover:shadow-xl hover:border-zinc-700 transition-all flex flex-col h-full group cursor-pointer"
>
{/* Image Showcase */}
<div className="relative aspect-[4/5] bg-zinc-950 overflow-hidden flex items-center justify-center">
{/* eslint-disable-next-line @next/next/no-img-element */}
<img
src={creation.resultImage}
alt="Simulated Hairstyle"
className="w-full h-full object-cover group-hover:scale-105 transition-transform duration-300"
/>
{/* Hover Eye indicator */}
<div className="absolute inset-0 bg-black/40 opacity-0 group-hover:opacity-100 flex items-center justify-center transition-opacity">
<div className="h-10 w-10 bg-zinc-900 border border-zinc-700 rounded-full flex items-center justify-center text-white shadow-lg">
<FaEye />
</div>
</div>
{/* Floating parameters badge */}
<span className="absolute top-3 left-3 text-[8px] font-bold text-violet-300 bg-zinc-950 border border-zinc-800 px-2 py-0.5 rounded-lg shadow uppercase">
{creation.colorName} • {creation.styleName}
</span>
</div>
{/* Card footer details */}
<div className="p-4 bg-zinc-900 border-t border-zinc-800 flex items-center justify-between text-[10px] text-zinc-400 font-bold">
<span>
{new Date(creation.createTime).toLocaleDateString(undefined, { month: "short", day: "numeric" })}
</span>
<div className="flex items-center gap-3">
<button
onClick={(e) => {
e.stopPropagation();
handleDownload(creation);
}}
className="text-zinc-400 hover:text-white transition-colors flex items-center gap-1 font-bold cursor-pointer"
title="Download HD"
>
<FaDownload />
<span>HD</span>
</button>
<button
onClick={(e) => {
e.stopPropagation();
handleDelete(creation.id);
}}
disabled={deletingId === creation.id}
className="text-zinc-400 hover:text-red-400 transition-colors flex items-center gap-1 font-bold disabled:opacity-50 cursor-pointer"
title="Delete Simulation"
>
{deletingId === creation.id ? (
<FaSpinner className="animate-spin text-[9px]" />
) : (
<FaTrashAlt />
)}
<span>Delete</span>
</button>
</div>
</div>
</div>
))}
</div>
)}
{/* ─── Detail Modal overlay ────────────────────── */}
{selectedCreation && (
<div className="fixed inset-0 z-50 flex items-center justify-center p-4 sm:p-6 bg-black/85 backdrop-blur-md transition-opacity" onClick={() => setSelectedCreation(null)}>
<div className="bg-zinc-900 border border-zinc-800 rounded-2xl max-w-lg w-full p-5 sm:p-6 shadow-2xl relative animate-in fade-in zoom-in duration-200 flex flex-col overflow-hidden max-h-[90vh]" onClick={(e) => e.stopPropagation()}>
{/* Modal header */}
<div className="flex items-center justify-between border-b border-zinc-800 pb-3 mb-4 flex-shrink-0">
<div>
<h3 className="text-sm sm:text-base font-bold font-heading text-white flex items-center gap-2">
<span>Hairstyle Details</span>
<span className="text-[9px] font-bold text-violet-400 bg-violet-950 border border-violet-850 px-2 py-0.5 rounded-lg uppercase">
{selectedCreation.colorName} • {selectedCreation.styleName}
</span>
</h3>
</div>
<button
onClick={() => setSelectedCreation(null)}
className="text-zinc-400 hover:text-white font-bold text-sm p-1.5 hover:bg-zinc-800 rounded-lg transition-all cursor-pointer"
>
✕
</button>
</div>
{/* Modal Display Area */}
<div className="flex-1 flex items-center justify-center overflow-hidden min-h-0 relative select-none">
<div className="relative w-full aspect-[4/5] rounded-xl overflow-hidden border border-zinc-800 bg-zinc-950 shadow-md select-none max-h-[60vh] max-w-sm">
{/* Result image */}
{/* eslint-disable-next-line @next/next/no-img-element */}
<img
src={selectedCreation.resultImage}
alt="Simulated result"
className="w-full h-full object-cover pointer-events-none"
/>
{/* Input reference overlay badge */}
<div className="absolute bottom-3 right-3 bg-zinc-900/95 border border-zinc-800 p-2.5 rounded-lg flex flex-col gap-1.5 z-20 shadow-lg max-w-[100px] backdrop-blur">
<span className="text-[7px] font-bold text-zinc-400 uppercase tracking-wider">Before</span>
<div className="h-10 w-8 rounded overflow-hidden border border-zinc-800 bg-zinc-950">
{/* eslint-disable-next-line @next/next/no-img-element */}
<img src={selectedCreation.inputImage} alt="Selfie" className="w-full h-full object-cover" />
</div>
</div>
{/* Label badge */}
<div className="absolute top-3 left-3 bg-zinc-950/90 backdrop-blur border border-zinc-800 text-violet-400 text-[8px] font-bold uppercase tracking-wider px-2 py-0.5 rounded-lg z-20">
Simulated Look
</div>
</div>
</div>
{/* Modal Actions Footer */}
<div className="border-t border-zinc-800 pt-4 mt-4 flex justify-between items-center gap-3 flex-shrink-0">
<button
onClick={() => handleDelete(selectedCreation.id)}
disabled={deletingId === selectedCreation.id}
className="px-4 py-2 bg-red-950/20 hover:bg-red-900/30 text-red-400 border border-red-900/30 rounded-lg text-xs font-bold transition-all cursor-pointer flex items-center gap-1.5"
>
<FaTrashAlt className="text-[10px]" /> Delete Result
</button>
<div className="flex gap-2">
<button
onClick={() => handleDownload(selectedCreation)}
className="px-4 py-2 bg-gradient-to-r from-violet-600 to-fuchsia-600 hover:from-violet-500 hover:to-fuchsia-500 text-white rounded-lg text-xs font-bold shadow-lg transition-all cursor-pointer flex items-center gap-1.5 hover:scale-[1.02]"
>
<FaDownload className="text-[10px]" /> Download HD
</button>
<button
onClick={() => setSelectedCreation(null)}
className="px-4 py-2 bg-zinc-800 hover:bg-zinc-700 text-zinc-300 rounded-lg text-xs font-bold transition-all cursor-pointer"
>
Close
</button>
</div>
</div>
</div>
</div>
)}
</div>
</div>
);
}