+ {results && results.clips && results.clips.length > 0 ? (
+
+ {results.clips.map((clip, i) => (
+ handleClipPlay(time)}
+ onPause={handleClipPause}
+ />
+ ))}
+
+ ) : (
status === 'processing' ? (
diff --git a/dashboard/src/components/Gallery.jsx b/dashboard/src/components/Gallery.jsx
new file mode 100644
index 0000000..eb41e3f
--- /dev/null
+++ b/dashboard/src/components/Gallery.jsx
@@ -0,0 +1,147 @@
+import React, { useState, useEffect, useRef, useCallback } from 'react';
+import { LayoutGrid, AlertCircle, Loader2 } from 'lucide-react';
+import { getApiUrl } from '../config';
+import GalleryCard from './GalleryCard';
+
+const CLIPS_PER_PAGE = 20;
+
+export default function Gallery() {
+ const [clips, setClips] = useState([]);
+ const [loading, setLoading] = useState(true);
+ const [loadingMore, setLoadingMore] = useState(false);
+ const [error, setError] = useState(null);
+ const [hasMore, setHasMore] = useState(true);
+ const [offset, setOffset] = useState(0);
+
+ const loaderRef = useRef(null);
+
+ const fetchClips = useCallback(async (currentOffset = 0, append = false) => {
+ try {
+ if (currentOffset === 0) setLoading(true);
+ else setLoadingMore(true);
+
+ const res = await fetch(
+ getApiUrl(`/api/gallery/clips?limit=${CLIPS_PER_PAGE}&offset=${currentOffset}`)
+ );
+ if (!res.ok) throw new Error('Failed to fetch clips');
+ const data = await res.json();
+
+ const newClips = data.clips || [];
+
+ if (append) {
+ setClips(prev => [...prev, ...newClips]);
+ } else {
+ setClips(newClips);
+ }
+
+ setHasMore(data.has_more ?? newClips.length === CLIPS_PER_PAGE);
+ setOffset(currentOffset + newClips.length);
+ } catch (err) {
+ setError(err.message);
+ } finally {
+ setLoading(false);
+ setLoadingMore(false);
+ }
+ }, []);
+
+ // Initial load
+ useEffect(() => {
+ fetchClips(0, false);
+ }, [fetchClips]);
+
+ // Infinite scroll observer
+ useEffect(() => {
+ if (!hasMore || loadingMore || loading) return;
+
+ const observer = new IntersectionObserver(
+ (entries) => {
+ if (entries[0].isIntersecting && hasMore && !loadingMore) {
+ fetchClips(offset, true);
+ }
+ },
+ { rootMargin: '200px', threshold: 0.1 }
+ );
+
+ if (loaderRef.current) {
+ observer.observe(loaderRef.current);
+ }
+
+ return () => {
+ if (loaderRef.current) {
+ observer.unobserve(loaderRef.current);
+ }
+ };
+ }, [hasMore, loadingMore, loading, offset, fetchClips]);
+
+ if (loading) {
+ return (
+
+
+
Loading your viral history...
+
+ );
+ }
+
+ if (error) {
+ return (
+
+
+
Error loading gallery: {error}
+
+
+ );
+ }
+
+ return (
+
+
+
+ Clip Gallery
+
+
+ {clips.length} {clips.length === 1 ? 'Clip' : 'Clips'}{hasMore ? '+' : ''}
+
+
+
+ {clips.length === 0 ? (
+
+
No clips found yet.
+
Process some videos to populate your gallery!
+
+ ) : (
+ <>
+
+ {clips.map((clip, i) => (
+
+ ))}
+
+
+ {/* Infinite scroll loader trigger */}
+ {hasMore && (
+
+ {loadingMore && (
+
+
+ Loading more clips...
+
+ )}
+
+ )}
+ >
+ )}
+
+ );
+}
+
diff --git a/dashboard/src/components/GalleryCard.jsx b/dashboard/src/components/GalleryCard.jsx
new file mode 100644
index 0000000..eafdd19
--- /dev/null
+++ b/dashboard/src/components/GalleryCard.jsx
@@ -0,0 +1,156 @@
+import React, { useRef, useState, useEffect } from 'react';
+import { Download, Youtube, Instagram, Video, Copy, Check, Play } from 'lucide-react';
+
+export default function GalleryCard({ clip }) {
+ const [copied, setCopied] = useState(null);
+ const [isVisible, setIsVisible] = useState(false);
+ const [hasLoaded, setHasLoaded] = useState(false);
+ const cardRef = useRef(null);
+ const videoRef = useRef(null);
+
+ // Lazy loading with IntersectionObserver
+ useEffect(() => {
+ const observer = new IntersectionObserver(
+ (entries) => {
+ entries.forEach((entry) => {
+ if (entry.isIntersecting) {
+ setIsVisible(true);
+ // Once loaded, we don't need to observe anymore
+ observer.unobserve(entry.target);
+ }
+ });
+ },
+ {
+ rootMargin: '200px', // Start loading 200px before entering viewport
+ threshold: 0.1
+ }
+ );
+
+ if (cardRef.current) {
+ observer.observe(cardRef.current);
+ }
+
+ return () => {
+ if (cardRef.current) {
+ observer.unobserve(cardRef.current);
+ }
+ };
+ }, []);
+
+ const handleCopy = (text, field) => {
+ navigator.clipboard.writeText(text);
+ setCopied(field);
+ setTimeout(() => setCopied(null), 2000);
+ };
+
+ const handleDownload = async (e) => {
+ e.preventDefault();
+ try {
+ const response = await fetch(clip.url);
+ if (!response.ok) throw new Error('Download failed');
+ const blob = await response.blob();
+ const url = window.URL.createObjectURL(blob);
+ const a = document.createElement('a');
+ a.style.display = 'none';
+ a.href = url;
+ a.download = `clip_${clip.job_id}_${clip.index + 1}.mp4`;
+ document.body.appendChild(a);
+ a.click();
+ window.URL.revokeObjectURL(url);
+ document.body.removeChild(a);
+ } catch (err) {
+ console.error('Download error:', err);
+ window.open(clip.url, '_blank');
+ }
+ };
+
+ return (
+
+ {/* Video Player - Lazy loaded */}
+
+ {isVisible ? (
+
+
+ {/* Content & Details */}
+
+
+
+ {clip.title}
+
+
+ {clip.duration.toFixed(1)}s
+ ID: {clip.job_id.substring(0, 8)}
+
+
+
+
+ {/* YouTube Title */}
+
+
+ YouTube Title
+
+
{clip.title}
+
+
+
+ {/* TikTok / IG Caption */}
+
+
+
+ /
+ Caption
+
+
+ {clip.tiktok_desc || clip.insta_desc}
+
+
+
+
+
+ {/* Footer Action */}
+
+
+
+ );
+}
diff --git a/dashboard/src/components/HookModal.jsx b/dashboard/src/components/HookModal.jsx
new file mode 100644
index 0000000..93a896f
--- /dev/null
+++ b/dashboard/src/components/HookModal.jsx
@@ -0,0 +1,140 @@
+import React, { useState } from 'react';
+import { X, Sparkles, Loader2, Maximize, MoveVertical } from 'lucide-react';
+
+export default function HookModal({ isOpen, onClose, onGenerate, isProcessing, videoUrl, initialText }) {
+ const [text, setText] = useState(initialText || 'POV: You are using the viral hook feature');
+ const [position, setPosition] = useState('top'); // top, center, bottom
+ const [size, setSize] = useState('M'); // S, M, L
+
+ if (!isOpen) return null;
+
+ // Preview Logic
+ const getPositionClass = () => {
+ switch (position) {
+ case 'center': return 'items-center justify-center';
+ case 'bottom': return 'items-center justify-end pb-[20%]';
+ case 'top': default: return 'items-center justify-start pt-[20%]';
+ }
+ };
+
+ const getSizeStyle = () => {
+ switch (size) {
+ case 'S': return { fontSize: '14px', maxWidth: '80%' };
+ case 'L': return { fontSize: '24px', maxWidth: '95%' };
+ case 'M': default: return { fontSize: '18px', maxWidth: '90%' };
+ }
+ };
+
+ return (
+
+
+
+
+ {/* Left: Preview */}
+
+
+
+ {/* Hook Overlay Preview */}
+
+
+ {text || "Enter your text..."}
+
+
+
+
+ {/* Right: Controls */}
+
+
+ Viral Hook
+
+
+
+ {/* Text Input */}
+
+
+
+
+ {/* Position Control */}
+
+
+
+ {['top', 'center', 'bottom'].map((pos) => (
+
+ ))}
+
+
+
+ {/* Size Control */}
+
+
+
+ {['S', 'M', 'L'].map((sz) => (
+
+ ))}
+
+
+
+
+ Tip: Keep it short and punchy. Using "POV:" or specific questions works best for retention.
+
+
+
+
+
+
+
+ );
+}
diff --git a/dashboard/src/components/ResultCard.jsx b/dashboard/src/components/ResultCard.jsx
index 76e4dc3..676e397 100644
--- a/dashboard/src/components/ResultCard.jsx
+++ b/dashboard/src/components/ResultCard.jsx
@@ -2,6 +2,7 @@ import React, { useState, useEffect } from 'react';
import { Download, Share2, Instagram, Youtube, Video, CheckCircle, AlertCircle, X, Loader2, Copy, Wand2, Type, Calendar, Clock } from 'lucide-react';
import { getApiUrl } from '../config';
import SubtitleModal from './SubtitleModal';
+import HookModal from './HookModal';
export default function ResultCard({ clip, index, jobId, uploadPostKey, uploadUserId, geminiApiKey, onPlay, onPause }) {
const [showModal, setShowModal] = useState(false);
@@ -24,6 +25,8 @@ export default function ResultCard({ clip, index, jobId, uploadPostKey, uploadUs
const [isEditing, setIsEditing] = useState(false);
const [isSubtitling, setIsSubtitling] = useState(false);
+ const [isHooking, setIsHooking] = useState(false);
+ const [showHookModal, setShowHookModal] = useState(false);
const [editError, setEditError] = useState(null);
// Initialize/Reset form when modal opens
@@ -41,44 +44,44 @@ export default function ResultCard({ clip, index, jobId, uploadPostKey, uploadUs
setIsEditing(true);
setEditError(null);
try {
- // Use passed prop or fallback
- const apiKey = geminiApiKey || localStorage.getItem('gemini_key');
-
- if (!apiKey) {
- throw new Error("Gemini API Key is missing. Please set it in Settings.");
- }
+ // Use passed prop or fallback
+ const apiKey = geminiApiKey || localStorage.getItem('gemini_key');
- const res = await fetch(getApiUrl('/api/edit'), {
+ if (!apiKey) {
+ throw new Error("Gemini API Key is missing. Please set it in Settings.");
+ }
+
+ const res = await fetch(getApiUrl('/api/edit'), {
method: 'POST',
- headers: {
+ headers: {
'Content-Type': 'application/json',
- 'X-Gemini-Key': apiKey
+ 'X-Gemini-Key': apiKey
},
body: JSON.stringify({
job_id: jobId,
clip_index: index,
input_filename: currentVideoUrl.split('/').pop()
})
- });
+ });
- if (!res.ok) {
- const errText = await res.text();
- try {
- const jsonErr = JSON.parse(errText);
- throw new Error(jsonErr.detail || errText);
- } catch (e) {
- throw new Error(errText);
- }
- }
+ if (!res.ok) {
+ const errText = await res.text();
+ try {
+ const jsonErr = JSON.parse(errText);
+ throw new Error(jsonErr.detail || errText);
+ } catch (e) {
+ throw new Error(errText);
+ }
+ }
- const data = await res.json();
- if (data.new_video_url) {
- setCurrentVideoUrl(getApiUrl(data.new_video_url));
- // Reload video
- if (videoRef.current) {
- videoRef.current.load();
- }
- }
+ const data = await res.json();
+ if (data.new_video_url) {
+ setCurrentVideoUrl(getApiUrl(data.new_video_url));
+ // Reload video
+ if (videoRef.current) {
+ videoRef.current.load();
+ }
+ }
} catch (e) {
setEditError(e.message);
@@ -126,6 +129,50 @@ export default function ResultCard({ clip, index, jobId, uploadPostKey, uploadUs
}
};
+ const handleHook = async (hookData) => {
+ setIsHooking(true);
+ setEditError(null);
+ try {
+ // Support both string (legacy) and object
+ const payload = typeof hookData === 'string'
+ ? { text: hookData, position: 'top', size: 'M' }
+ : hookData;
+
+ const res = await fetch(getApiUrl('/api/hook'), {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({
+ job_id: jobId,
+ clip_index: index,
+ text: payload.text,
+ position: payload.position,
+ size: payload.size,
+ input_filename: currentVideoUrl.split('/').pop()
+ })
+ });
+
+ if (!res.ok) {
+ const errText = await res.text();
+ throw new Error(errText);
+ }
+
+ const data = await res.json();
+ if (data.new_video_url) {
+ setCurrentVideoUrl(getApiUrl(data.new_video_url));
+ if (videoRef.current) {
+ videoRef.current.load();
+ }
+ setShowHookModal(false);
+ }
+
+ } catch (e) {
+ setEditError(e.message);
+ setTimeout(() => setEditError(null), 5000);
+ } finally {
+ setIsHooking(false);
+ }
+ };
+
const handlePost = async () => {
if (!uploadPostKey || !uploadUserId) {
setPostResult({ success: false, msg: "Missing API Key or User ID." });
@@ -220,7 +267,7 @@ export default function ResultCard({ clip, index, jobId, uploadPostKey, uploadUs
Clip {index + 1}
-
+
{/* Auto Edit Overlay if Processing */}
{isEditing && (