From 0b8344702412cc558a50154f14d52516a0ec5dfb Mon Sep 17 00:00:00 2001 From: pollutri Date: Fri, 8 May 2026 10:54:16 +0200 Subject: [PATCH] Layout update per il video player --- components/PublicGrid.tsx | 78 ++++++++++++++++++++++++++++++--------- 1 file changed, 61 insertions(+), 17 deletions(-) diff --git a/components/PublicGrid.tsx b/components/PublicGrid.tsx index 532f28b..1574980 100644 --- a/components/PublicGrid.tsx +++ b/components/PublicGrid.tsx @@ -12,9 +12,20 @@ function MediaCarousel({ onMediaClick?: (index: number) => void; }) { const [current, setCurrent] = useState(0); + const [playing, setPlaying] = useState>(new Set()); const touchStartX = useRef(null); const videoRefs = useRef>({}); + const markPlaying = (i: number) => setPlaying(p => { const n = new Set(p); n.add(i); return n; }); + const markPaused = (i: number) => setPlaying(p => { const n = new Set(p); n.delete(i); return n; }); + + const togglePlay = (i: number) => { + const v = videoRefs.current[i]; + if (!v) return; + if (v.paused) v.play().catch(() => {}); + else v.pause(); + }; + const prev = useCallback(() => setCurrent(i => (i - 1 + items.length) % items.length), [items.length]); const next = useCallback(() => setCurrent(i => (i + 1) % items.length), [items.length]); @@ -70,18 +81,28 @@ function MediaCarousel({ className={`absolute inset-0 transition-opacity duration-300 ${isActive ? 'opacity-100' : 'opacity-0 pointer-events-none'}`} > {video ? ( - <> +
{ e.stopPropagation(); togglePlay(i); }} + >
) : ( void; }) { const [current, setCurrent] = useState(startIndex); + const [playing, setPlaying] = useState>(new Set()); const touchStartX = useRef(null); + const videoRefs = useRef>({}); + + const markPlaying = (i: number) => setPlaying(p => { const n = new Set(p); n.add(i); return n; }); + const markPaused = (i: number) => setPlaying(p => { const n = new Set(p); n.delete(i); return n; }); + + const togglePlay = (i: number) => { + const v = videoRefs.current[i]; + if (!v) return; + if (v.paused) v.play().catch(() => {}); + else v.pause(); + }; const prev = useCallback(() => setCurrent(i => (i - 1 + items.length) % items.length), [items.length]); const next = useCallback(() => setCurrent(i => (i + 1) % items.length), [items.length]); @@ -188,16 +221,27 @@ function FullscreenViewer({ className={`absolute inset-0 flex items-center justify-center p-4 pb-28 transition-opacity duration-200 ${isActive ? 'opacity-100' : 'opacity-0 pointer-events-none'}`} > {video ? ( -