import { Link, useSearchParams } from 'react-router'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { fileUrl } from '../lib/api'; import type { CollectionSummary, GenerationRow } from '../lib/api'; import { useCollectionsManager } from './useCollectionsManager'; import type { CollectionsManager } from './useCollectionsManager'; export const Collections = () => { const [searchParams] = useSearchParams(); const openId = searchParams.get('collection') ?? undefined; const manager = useCollectionsManager(openId); if (manager.loading) return

Loading…

; if (openId) return ; return (
manager.setDraftName(ev.target.value)} onKeyDown={(ev) => ev.key === 'Enter' && manager.create()} />
{manager.error &&

{manager.error}

} {manager.collections.length === 0 ? (

No collections yet. Create one here, or pass ?collection=name{' '} when generating and it will be made for you.

) : (
{manager.collections.map((collection) => ( manager.remove(collection.id)} /> ))}
)}
); }; type CardProps = { collection: CollectionSummary; searchParams: URLSearchParams; onDelete: () => void }; const Card = ({ collection, searchParams, onDelete }: CardProps) => { const src = fileUrl(collection.cover_url); const to = (() => { const next = new URLSearchParams(searchParams); next.set('collection', collection.id); return { search: `?${next.toString()}` }; })(); return (
{src ? ( ) : ( empty )}

{collection.name}

{collection.item_count} image{collection.item_count === 1 ? '' : 's'}

); }; type DetailProps = { manager: CollectionsManager; searchParams: URLSearchParams }; const Detail = ({ manager, searchParams }: DetailProps) => { const collection = manager.detail; const backTo = (() => { const next = new URLSearchParams(searchParams); next.delete('collection'); const search = next.toString(); return { search: search ? `?${search}` : '' }; })(); if (!collection) return

Loading…

; return (
‹ Collections

{collection.name}

{collection.images.length} image{collection.images.length === 1 ? '' : 's'}
{collection.images.length === 0 ? (

Nothing here yet. Add images from the gallery, or generate with{' '} ?collection={collection.name}.

) : (
{collection.images.map((image) => ( manager.removeImage(collection.id, image.id)} /> ))}
)}
); }; const Item = ({ image, onRemove }: { image: GenerationRow; onRemove: () => void }) => { const src = fileUrl(image.url); return (
{src ? ( {image.prompt} ) : ( {image.error ?? image.status} )}
{image.prompt}
); };