// @ts-nocheck import React from 'react'; import { Link } from 'react-router-dom'; import { Card, CardContent } from '@/components/ui/card'; import { getDeviceId } from '../lib/device'; import { usePollGalleryDelta } from '../polling/usePollGalleryDelta'; import { Heart } from 'lucide-react'; import { useTranslation } from '../i18n/useTranslation'; import { useEventBranding } from '../context/EventBrandingContext'; type Props = { token: string }; type PreviewFilter = 'latest' | 'popular' | 'mine' | 'photobooth'; type PreviewPhoto = { id: number; session_id?: string | null; ingest_source?: string | null; likes_count?: number | null; created_at?: string | null; task_id?: number | null; task_title?: string | null; emotion_id?: number | null; emotion_name?: string | null; thumbnail_path?: string | null; file_path?: string | null; title?: string | null; }; export default function GalleryPreview({ token }: Props) { const { locale } = useTranslation(); const { branding } = useEventBranding(); const { photos, loading } = usePollGalleryDelta(token, locale); const [mode, setMode] = React.useState('latest'); const typedPhotos = React.useMemo(() => photos as PreviewPhoto[], [photos]); const hasPhotobooth = React.useMemo(() => typedPhotos.some((p) => p.ingest_source === 'photobooth'), [typedPhotos]); const radius = branding.buttons?.radius ?? 12; const linkColor = branding.buttons?.linkColor ?? branding.secondaryColor; const headingFont = branding.typography?.heading ?? branding.fontFamily ?? undefined; const bodyFont = branding.typography?.body ?? branding.fontFamily ?? undefined; const items = React.useMemo(() => { let arr = typedPhotos.slice(); // MyPhotos filter (requires session_id matching) if (mode === 'mine') { const deviceId = getDeviceId(); arr = arr.filter((photo) => photo.session_id === deviceId); } else if (mode === 'photobooth') { arr = arr.filter((photo) => photo.ingest_source === 'photobooth'); } // Sorting if (mode === 'popular') { arr.sort((a, b) => (b.likes_count ?? 0) - (a.likes_count ?? 0)); } else { arr.sort((a, b) => new Date(b.created_at ?? 0).getTime() - new Date(a.created_at ?? 0).getTime()); } return arr.slice(0, 4); // 2x2 = 4 items }, [typedPhotos, mode]); React.useEffect(() => { if (mode === 'photobooth' && !hasPhotobooth) { setMode('latest'); } }, [mode, hasPhotobooth]); // Helper function to generate photo title (must be before return) function getPhotoTitle(photo: PreviewPhoto): string { if (photo.task_id) { return `Task: ${photo.task_title || 'Unbekannte Aufgabe'}`; } if (photo.emotion_id) { return `Emotion: ${photo.emotion_name || 'Gefühl'}`; } // Fallback based on creation time or placeholder const now = new Date(); const created = new Date(photo.created_at || now); const hours = created.getHours(); if (hours < 12) return 'Morgenmoment'; if (hours < 18) return 'Nachmittagslicht'; return 'Abendstimmung'; } const filters: { value: PreviewFilter; label: string }[] = [ { value: 'latest', label: 'Newest' }, { value: 'popular', label: 'Popular' }, { value: 'mine', label: 'My Photos' }, ...(hasPhotobooth ? [{ value: 'photobooth', label: 'Fotobox' } as const] : []), ]; return (

Live-Galerie

Alle Uploads auf einen Blick

Alle ansehen →
{filters.map((filter) => ( ))}
{loading &&

Lädt…

} {!loading && items.length === 0 && (
Noch keine Fotos. Starte mit deinem ersten Upload!
)}
{items.map((p: PreviewPhoto) => ( {p.title

{p.title || getPhotoTitle(p)}

{p.likes_count ?? 0}
))}

Lust auf mehr?{' '} Zur Galerie →

); }