import React, { useState, useEffect } from 'react'; import { Film, Download, Copy, Check, 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 [loadingVideos, setLoadingVideos] = useState(true); const [loadingAvatars, setLoadingAvatars] = useState(false); const [avatarsLoaded, setAvatarsLoaded] = useState(false); const [copied, setCopied] = useState(''); const [selected, setSelected] = useState(null); useEffect(() => { setLoadingVideos(true); fetch(getApiUrl('/api/saasshorts/gallery?limit=100')) .then((r) => (r.ok ? r.json() : { videos: [] })) .then((d) => setVideos(d.videos || [])) .catch(() => {}) .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); }; const loading = (tab === 'videos' && loadingVideos) || (tab === 'avatars' && loadingAvatars); return (

05 · UGC GALLERY

ugc gallery

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

}, { value: 'avatars', label: `Avatars (${avatarsLoaded ? avatars.length : '…'})`, icon: }, ]} />
{loading ? (
Loading gallery...
) : tab === 'videos' ? ( videos.length === 0 ? (

No videos yet. Generate one from AI Shorts.

) : (
{videos.map((video) => ( setSelected(video)} /> ))}
) ) : 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'} > )}
); } function AvatarCard({ avatar, copied, onCopy }) { return (
Avatar
{avatar.description ? (

{avatar.description}

) : (

No description

)} Download
); } function VideoCard({ video, copied, onCopy, onOpen }) { const mode = video.video_mode; const caption = video.caption || ''; const hashtags = (video.hashtags || []).join(' '); return (

{video.title || 'Untitled'}

{video.duration?.toFixed(0)}s · ${video.cost_estimate?.total?.toFixed(2) || '?'}

{caption && (

{caption}

)} Download
); }