import { useCallback, useEffect, useState } from "react"; import { useParams } from "react-router-dom"; import { getPhotoWallPresent, type PhotoWallPresentData } from "../lib/api"; const POLL_MS = 4000; export function PhotoWallPresentPage() { const { presentToken } = useParams<{ presentToken: string }>(); const [data, setData] = useState(null); const [err, setErr] = useState(null); const [loading, setLoading] = useState(true); const refresh = useCallback(async () => { if (!presentToken) return; try { const next = await getPhotoWallPresent(presentToken); setData(next); setErr(null); } catch (e) { setErr(e instanceof Error ? e.message : "Photo wall not available"); setData(null); } finally { setLoading(false); } }, [presentToken]); useEffect(() => { void refresh(); const id = window.setInterval(() => void refresh(), POLL_MS); return () => window.clearInterval(id); }, [refresh]); if (loading) { return (
Loading wall…
); } if (!data) { return (

Photo wall unavailable

{err}

); } const cols = Math.max(1, Math.min(12, data.photosPerRow || 4)); const maxW = data.maxPhotoWidth || 320; const maxH = data.maxPhotoHeight || 320; const gap = data.gapPx ?? 8; const showNames = Boolean(data.showUploaderNameOnWall); const frameEnabled = Boolean(data.frameEnabled); const frameW = data.frameCanvasWidth || 1080; const frameH = data.frameCanvasHeight || 1080; const aspectRatio = frameEnabled ? `${frameW} / ${frameH}` : `${maxW} / ${maxH}`; return (

Photo Wall

{data.eventName}

{data.photos.length === 0 ? (
Waiting for photos…
) : (
{data.photos.map((p) => (
{showNames && p.displayName ? (

{p.displayName}

) : null}
))}
)}
); }