From 9d69bea94019ea50c71b20a2c4d6338c671150c5 Mon Sep 17 00:00:00 2001 From: "victormanuel.caverogracia" <> Date: Tue, 1 Sep 2026 10:27:27 +0200 Subject: [PATCH] fix(dashboard): play UGC gallery clips in a modal Cards were mounting every mp4 with preload=metadata, so the grid stalled, and click did nothing except a hidden View link that opened another tab. Posters only until click; playback stays on the same screen. --- dashboard/src/components/UGCGallery.jsx | 212 +++++++++++++----------- 1 file changed, 115 insertions(+), 97 deletions(-) diff --git a/dashboard/src/components/UGCGallery.jsx b/dashboard/src/components/UGCGallery.jsx index 623bf00..43a1b0f 100644 --- a/dashboard/src/components/UGCGallery.jsx +++ b/dashboard/src/components/UGCGallery.jsx @@ -1,52 +1,59 @@ -import React, { useState, useEffect, useRef } from 'react'; +import React, { useState, useEffect } from 'react'; import { Film, Download, Copy, Check, ExternalLink, Loader2, Play, User } from 'lucide-react'; import { getApiUrl } from '../config'; import SegmentedControl from './ui/SegmentedControl'; +import Modal from './ui/Modal'; export default function UGCGallery() { const [tab, setTab] = useState('videos'); const [videos, setVideos] = useState([]); const [avatars, setAvatars] = useState([]); - const [loading, setLoading] = useState(true); + const [loadingVideos, setLoadingVideos] = useState(true); + const [loadingAvatars, setLoadingAvatars] = useState(false); + const [avatarsLoaded, setAvatarsLoaded] = useState(false); const [copied, setCopied] = useState(''); + const [selected, setSelected] = useState(null); useEffect(() => { - setLoading(true); - Promise.all([ - fetch(getApiUrl('/api/saasshorts/gallery?limit=100')).then(r => r.ok ? r.json() : { videos: [] }), - fetch(getApiUrl('/api/saasshorts/actor-gallery')).then(r => r.ok ? r.json() : { images: [] }), - ]) - .then(([vData, aData]) => { - setVideos(vData.videos || []); - setAvatars(aData.images || []); - }) + setLoadingVideos(true); + fetch(getApiUrl('/api/saasshorts/gallery?limit=100')) + .then((r) => (r.ok ? r.json() : { videos: [] })) + .then((d) => setVideos(d.videos || [])) .catch(() => {}) - .finally(() => setLoading(false)); + .finally(() => setLoadingVideos(false)); }, []); + useEffect(() => { + if (tab !== 'avatars' || avatarsLoaded) return; + setLoadingAvatars(true); + fetch(getApiUrl('/api/saasshorts/actor-gallery')) + .then((r) => (r.ok ? r.json() : { images: [] })) + .then((d) => setAvatars(d.images || [])) + .catch(() => {}) + .finally(() => { + setLoadingAvatars(false); + setAvatarsLoaded(true); + }); + }, [tab, avatarsLoaded]); + const handleCopy = (text, id) => { navigator.clipboard.writeText(text); setCopied(id); setTimeout(() => setCopied(''), 2000); }; - if (loading) { - return ( -
- - Loading gallery... -
- ); - } + const loading = (tab === 'videos' && loadingVideos) || (tab === 'avatars' && loadingAvatars); return (
- {/* Header */}

04 · UGC GALLERY

ugc gallery

-

{videos.length} videos · {avatars.length} avatars

+

+ {loadingVideos ? '…' : videos.length} videos + {avatarsLoaded ? ` · ${avatars.length} avatars` : ''} +

- {/* Tabs */}
}, - { value: 'avatars', label: `Avatars (${avatars.length})`, icon: }, + { value: 'videos', label: `Videos (${loadingVideos ? '…' : videos.length})`, icon: }, + { value: 'avatars', label: `Avatars (${avatarsLoaded ? avatars.length : '…'})`, icon: }, ]} />
- {/* Videos Tab */} - {tab === 'videos' && ( + {loading ? ( +
+ + Loading gallery... +
+ ) : tab === 'videos' ? ( videos.length === 0 ? (
@@ -81,26 +91,60 @@ export default function UGCGallery() { ) : (
{videos.map((video) => ( - + setSelected(video)} + /> ))}
) + ) : avatars.length === 0 ? ( +
+ +

No avatars yet. Generate actors from AI Shorts.

+
+ ) : ( +
+ {avatars.map((avatar, i) => ( + + ))} +
)} - {/* Avatars Tab */} - {tab === 'avatars' && ( - avatars.length === 0 ? ( -
- -

No avatars yet. Generate actors from AI Shorts.

-
- ) : ( -
- {avatars.map((avatar, i) => ( - - ))} -
- ) + {selected && ( + setSelected(null)} + size="sm" + eyebrow={selected.video_mode === 'lowcost' ? 'LOW COST' : 'PREMIUM'} + title={selected.title || 'Untitled'} + > +
+ Download + + )}
); @@ -110,13 +154,14 @@ function AvatarCard({ avatar, copied, onCopy }) { return (
- Avatar + Avatar
{avatar.description ? (

{avatar.description}

{video.title || 'Untitled'}

@@ -199,6 +226,7 @@ function VideoCard({ video, copied, onCopy }) {

{caption}

)} - + + Download +
);