import React from 'react'; import { useNavigate, useSearchParams } from 'react-router-dom'; import { Camera, Loader2, Sparkles, Trash2 } from 'lucide-react'; import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert'; import { Button } from '@/components/ui/button'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; import { AdminLayout } from '../components/AdminLayout'; import { deletePhoto, featurePhoto, getEventPhotos, TenantPhoto, unfeaturePhoto } from '../api'; import { isAuthError } from '../auth/tokens'; export default function EventPhotosPage() { const [searchParams] = useSearchParams(); const slug = searchParams.get('slug'); const navigate = useNavigate(); const [photos, setPhotos] = React.useState([]); const [loading, setLoading] = React.useState(true); const [error, setError] = React.useState(null); const [busyId, setBusyId] = React.useState(null); const load = React.useCallback(async () => { if (!slug) { setLoading(false); return; } setLoading(true); setError(null); try { const data = await getEventPhotos(slug); setPhotos(data); } catch (err) { if (!isAuthError(err)) { setError('Fotos konnten nicht geladen werden.'); } } finally { setLoading(false); } }, [slug]); React.useEffect(() => { load(); }, [load]); async function handleToggleFeature(photo: TenantPhoto) { if (!slug) return; setBusyId(photo.id); try { const updated = photo.is_featured ? await unfeaturePhoto(slug, photo.id) : await featurePhoto(slug, photo.id); setPhotos((prev) => prev.map((entry) => (entry.id === photo.id ? updated : entry))); } catch (err) { if (!isAuthError(err)) { setError('Feature-Aktion fehlgeschlagen.'); } } finally { setBusyId(null); } } async function handleDelete(photo: TenantPhoto) { if (!slug) return; setBusyId(photo.id); try { await deletePhoto(slug, photo.id); setPhotos((prev) => prev.filter((entry) => entry.id !== photo.id)); } catch (err) { if (!isAuthError(err)) { setError('Foto konnte nicht entfernt werden.'); } } finally { setBusyId(null); } } if (!slug) { return ( Kein Slug in der URL gefunden. Kehre zur Event-Liste zurueck und waehle dort ein Event aus. ); } const actions = ( ); return ( {error && ( Aktion fehlgeschlagen {error} )} Galerie Klick auf ein Foto, um es hervorzuheben oder zu loeschen. {loading ? ( ) : photos.length === 0 ? ( ) : (
{photos.map((photo) => (
{photo.original_name {photo.is_featured && ( Featured )}
Likes: {photo.likes_count} Uploader: {photo.uploader_name ?? 'Unbekannt'}
))}
)}
); } function GallerySkeleton() { return (
{Array.from({ length: 6 }).map((_, index) => (
))}
); } function EmptyGallery() { return (

Noch keine Fotos vorhanden

Motiviere deine Gaeste zum Hochladen - hier erscheint anschliessend die Galerie.

); }