import { useEffect, useState } from 'react'; import { apiGet } from '../api.js'; import { IconChevronLeft, IconChevronRight, IconGallery } from '../icons.jsx'; import EmptyState from '../components/EmptyState.jsx'; import Lightbox from '../components/Lightbox.jsx'; import { SkeletonGrid } from '../components/Skeleton.jsx'; import { useT, useFmt } from '../i18n.jsx'; const DATUM = { day: '2-digit', month: '2-digit', year: 'numeric' }; export default function Galerie() { const { t } = useT(); const { datum } = useFmt(); const [data, setData] = useState(null); const [page, setPage] = useState(1); const [error, setError] = useState(false); const [lightbox, setLightbox] = useState(null); // Start-Index oder null useEffect(() => { setError(false); apiGet(`/api/gallery?page=${page}`).then(setData).catch(() => setError(true)); window.scrollTo(0, 0); }, [page]); const pages = data ? Math.ceil(data.total / data.pageSize) : 0; const shots = (data?.items ?? []).flatMap((item) => item.images.map((src) => ({ src, author: item.author_name, date: item.posted_at, key: src })) ); return ( <> GALERIE {t('gallery.tag')} {t('nav.gallery')} {t('gallery.subtitle')} {error && {t('gallery.error')}} {!error && !data && } {data?.total === 0 && ( )} {shots.map((s, i) => ( { e.preventDefault(); setLightbox(i); }} > {s.author} {datum(s.date, DATUM)} ))} {lightbox !== null && ( ({ src: s.src, caption: `${s.author} ยท ${datum(s.date, DATUM)}`, }))} start={lightbox} onClose={() => setLightbox(null)} /> )} {pages > 1 && ( setPage(page - 1)}> {t('common.newer')} {String(page).padStart(2, '0')} / {String(pages).padStart(2, '0')} = pages} onClick={() => setPage(page + 1)}> {t('common.older')} )} > ); }
{t('gallery.subtitle')}
{t('gallery.error')}