'use client'; import { useRouter } from 'next/navigation'; import { useState, useTransition } from 'react'; import { Camera, Loader2, Trash2 } from 'lucide-react'; import { toast } from 'sonner'; import { addSetPhoto, deletePhoto } from '@/app/(app)/katalog/actions'; import { fileUrl } from '@/lib/images'; import { Button } from '@/components/ui/button'; import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle, } from '@/components/ui/dialog'; import { Field } from '@/components/ui/field'; import { Input } from '@/components/ui/input'; export type PhotoRow = { id: string; filePath: string; thumbnailPath: string | null; caption: string | null; }; export function PhotosSection({ setId, photos }: { setId: string; photos: PhotoRow[] }) { const router = useRouter(); const [pending, startTransition] = useTransition(); const [addOpen, setAddOpen] = useState(false); function submit(event: React.FormEvent) { event.preventDefault(); const formData = new FormData(event.currentTarget); startTransition(async () => { const result = await addSetPhoto(setId, formData); if (!result.ok) { toast.error(result.error); return; } toast.success('Foto gespeichert.'); setAddOpen(false); router.refresh(); }); } function remove(id: string) { startTransition(async () => { const result = await deletePhoto(id); if (!result.ok) { toast.error(result.error); return; } toast.success('Foto gelöscht.'); router.refresh(); }); } return (
{photos.length > 0 ? ( ) : (

Noch keine eigenen Fotos – zum Beispiel vom fertig gebauten Modell.

)} Foto hinzufügen
{/* capture lets the phone open the camera directly. */}
); }