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 ( -
04 · UGC GALLERY
{videos.length} videos · {avatars.length} avatars
++ {loadingVideos ? '…' : videos.length} videos + {avatarsLoaded ? ` · ${avatars.length} avatars` : ''} +
No avatars yet. Generate actors from AI Shorts.
+No avatars yet. Generate actors from AI Shorts.
-+ {selected.duration?.toFixed(0)}s + {selected.cost_estimate?.total != null ? ` · $${selected.cost_estimate.total.toFixed(2)}` : ''} +
+ {selected.caption && ( +{selected.caption}
+ )} + +{avatar.description}