import { Link, useSearchParams } from 'react-router'; import { X } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { fileUrl } from '../lib/api'; import type { GenerationRow } from '../lib/api'; import { Lightbox } from './Lightbox'; import { useLightboxManager } from './useLightboxManager'; import { useGalleryManager } from './useGalleryManager'; /** * The main surface: every image, or one collection's images when `?collection=` is set. * * The collection view is HERE rather than in the Collections panel because that panel is a narrow * selector — showing a grid of images inside it meant two thumbnails per row, and it replaced the * list you were selecting from with the thing you selected. */ export const Gallery = () => { const [searchParams] = useSearchParams(); const collectionId = searchParams.get('collection') ?? undefined; const manager = useGalleryManager(collectionId); // Hooks run before any early return, or the order changes between renders. const lightbox = useLightboxManager(manager.rows); const allImagesTo = (() => { const next = new URLSearchParams(searchParams); next.delete('collection'); next.delete('selected'); const search = next.toString(); return { search: search ? `?${search}` : '' }; })(); if (manager.loading) return
Loading…
; if (manager.error) return{manager.error}
; return ({manager.succeeded.length} image{manager.succeeded.length === 1 ? '' : 's'} {manager.totalCost > 0 && ` · $${manager.totalCost.toFixed(4)} total`}
{manager.collection ? 'Nothing filed here yet.' : 'Nothing generated yet.'}
) : ({row.prompt}
{row.model} {row.cost_usd && ` · $${Number(row.cost_usd).toFixed(4)}`} {row.duration_ms != null && ` · ${(row.duration_ms / 1000).toFixed(1)}s`}