diff --git a/dashboard/src/App.jsx b/dashboard/src/App.jsx index c8cb0c1..6e6bf49 100644 --- a/dashboard/src/App.jsx +++ b/dashboard/src/App.jsx @@ -1,5 +1,5 @@ import React, { useState, useEffect } from 'react'; -import { Upload, FileVideo, Sparkles, Youtube, Instagram, Share2, LogOut, ChevronDown, Check, Activity, LayoutDashboard, Settings, PlusCircle, History, Menu, X, Terminal, Shield, LayoutGrid, Image, Globe, RotateCcw } from 'lucide-react'; +import { Upload, FileVideo, Sparkles, Youtube, Instagram, Share2, LogOut, ChevronDown, Check, Activity, LayoutDashboard, Settings, PlusCircle, History, Menu, X, Terminal, Shield, LayoutGrid, Image, Globe, RotateCcw, Calendar } from 'lucide-react'; import KeyInput from './components/KeyInput'; import MediaInput from './components/MediaInput'; import ResultCard from './components/ResultCard'; @@ -8,6 +8,7 @@ import ProcessingAnimation from './components/ProcessingAnimation'; import ThumbnailStudio from './components/ThumbnailStudio'; import SaaShortsTab from './components/SaaShortsTab'; import UGCGallery from './components/UGCGallery'; +import ScheduleWeekModal from './components/ScheduleWeekModal'; import { getApiUrl } from './config'; // Enhanced "Encryption" using XOR + Base64 with a Salt @@ -166,6 +167,7 @@ function App() { const [activeTab, setActiveTab] = useState('dashboard'); // dashboard, settings const [sessionRecovered, setSessionRecovered] = useState(false); + const [showScheduleWeek, setShowScheduleWeek] = useState(false); // Sync state for original video playback const [syncedTime, setSyncedTime] = useState(0); @@ -795,6 +797,15 @@ function App() { ${results.cost_analysis.total_cost.toFixed(5)} )} + {results?.clips?.length > 1 && status === 'complete' && ( + + )}
@@ -901,6 +912,15 @@ function App() {
)} + + setShowScheduleWeek(false)} + clips={results?.clips || []} + jobId={jobId} + uploadPostKey={uploadPostKey} + uploadUserId={uploadUserId} + /> ); } diff --git a/dashboard/src/components/ScheduleWeekModal.jsx b/dashboard/src/components/ScheduleWeekModal.jsx new file mode 100644 index 0000000..adc54ce --- /dev/null +++ b/dashboard/src/components/ScheduleWeekModal.jsx @@ -0,0 +1,388 @@ +import React, { useState, useMemo } from 'react'; +import { X, Loader2, Calendar, Clock, CheckCircle, AlertCircle, Video, Instagram, Youtube, ChevronLeft, ChevronRight, Globe, ExternalLink } from 'lucide-react'; +import { getApiUrl } from '../config'; + +const DAYS = ['Dom', 'Lun', 'Mar', 'Mié', 'Jue', 'Vie', 'Sáb']; +const MONTHS = ['Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Oct', 'Nov', 'Dic']; + +const TIMEZONES = [ + { value: 'Pacific/Midway', label: '(GMT-11:00) Midway' }, + { value: 'Pacific/Honolulu', label: '(GMT-10:00) Honolulu' }, + { value: 'America/Anchorage', label: '(GMT-09:00) Alaska' }, + { value: 'America/Los_Angeles', label: '(GMT-08:00) Los Ángeles' }, + { value: 'America/Denver', label: '(GMT-07:00) Denver' }, + { value: 'America/Mexico_City', label: '(GMT-06:00) Ciudad de México' }, + { value: 'America/Chicago', label: '(GMT-06:00) Chicago' }, + { value: 'America/New_York', label: '(GMT-05:00) Nueva York' }, + { value: 'America/Bogota', label: '(GMT-05:00) Bogotá' }, + { value: 'America/Caracas', label: '(GMT-04:00) Caracas' }, + { value: 'America/Santiago', label: '(GMT-04:00) Santiago' }, + { value: 'America/Argentina/Buenos_Aires', label: '(GMT-03:00) Buenos Aires' }, + { value: 'America/Sao_Paulo', label: '(GMT-03:00) São Paulo' }, + { value: 'Atlantic/Azores', label: '(GMT-01:00) Azores' }, + { value: 'UTC', label: '(GMT+00:00) UTC' }, + { value: 'Europe/London', label: '(GMT+00:00) Londres' }, + { value: 'Europe/Madrid', label: '(GMT+01:00) Madrid' }, + { value: 'Europe/Paris', label: '(GMT+01:00) París' }, + { value: 'Europe/Berlin', label: '(GMT+01:00) Berlín' }, + { value: 'Europe/Rome', label: '(GMT+01:00) Roma' }, + { value: 'Africa/Lagos', label: '(GMT+01:00) Lagos' }, + { value: 'Europe/Istanbul', label: '(GMT+03:00) Estambul' }, + { value: 'Asia/Dubai', label: '(GMT+04:00) Dubái' }, + { value: 'Asia/Kolkata', label: '(GMT+05:30) India' }, + { value: 'Asia/Bangkok', label: '(GMT+07:00) Bangkok' }, + { value: 'Asia/Shanghai', label: '(GMT+08:00) Shanghái' }, + { value: 'Asia/Tokyo', label: '(GMT+09:00) Tokio' }, + { value: 'Australia/Sydney', label: '(GMT+10:00) Sídney' }, + { value: 'Pacific/Auckland', label: '(GMT+12:00) Auckland' }, +]; + +function getDayLabel(date) { + const today = new Date(); + today.setHours(0, 0, 0, 0); + const tomorrow = new Date(today); + tomorrow.setDate(tomorrow.getDate() + 1); + const target = new Date(date); + target.setHours(0, 0, 0, 0); + + if (target.getTime() === today.getTime()) return 'Hoy'; + if (target.getTime() === tomorrow.getTime()) return 'Mañana'; + return DAYS[target.getDay()]; +} + +function formatDate(date) { + return `${date.getDate()} ${MONTHS[date.getMonth()]}`; +} + +function detectTimezone() { + try { + const tz = Intl.DateTimeFormat().resolvedOptions().timeZone; + if (TIMEZONES.find(t => t.value === tz)) return tz; + return 'UTC'; + } catch { + return 'UTC'; + } +} + +export default function ScheduleWeekModal({ isOpen, onClose, clips, jobId, uploadPostKey, uploadUserId }) { + const [time, setTime] = useState('12:00'); + const [timezone, setTimezone] = useState(detectTimezone); + const [platforms, setPlatforms] = useState({ + tiktok: true, + instagram: true, + youtube: true + }); + const [startOffset, setStartOffset] = useState(1); + + const schedule = useMemo(() => { + if (!clips) return []; + return clips.map((clip, i) => { + const date = new Date(); + date.setDate(date.getDate() + startOffset + i); + date.setHours(0, 0, 0, 0); + return { clip, index: i, date }; + }); + }, [clips, startOffset]); + + const [scheduling, setScheduling] = useState(false); + const [progress, setProgress] = useState({ current: 0, total: 0, results: [] }); + const [done, setDone] = useState(false); + + // Reset state when modal reopens + const prevOpen = React.useRef(false); + React.useEffect(() => { + if (isOpen && !prevOpen.current) { + setScheduling(false); + setDone(false); + setProgress({ current: 0, total: 0, results: [] }); + } + prevOpen.current = isOpen; + }, [isOpen]); + + if (!isOpen) return null; + + const selectedPlatforms = Object.keys(platforms).filter(k => platforms[k]); + + const handleScheduleAll = async () => { + if (!uploadPostKey || !uploadUserId) return; + if (selectedPlatforms.length === 0) return; + + setScheduling(true); + setDone(false); + const total = schedule.length; + setProgress({ current: 0, total, results: [] }); + + const results = []; + for (let i = 0; i < schedule.length; i++) { + const { clip, index, date } = schedule[i]; + + // Build local datetime string: "2026-04-06T12:00:00" + // Upload-Post accepts this + timezone IANA parameter + const pad = (n) => String(n).padStart(2, '0'); + const scheduledDate = `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}T${time}:00`; + + const payload = { + job_id: jobId, + clip_index: index, + api_key: uploadPostKey, + user_id: uploadUserId, + platforms: selectedPlatforms, + title: clip.video_title_for_youtube_short || 'Viral Short', + description: clip.video_description_for_instagram || clip.video_description_for_tiktok || '', + scheduled_date: scheduledDate, + timezone + }; + + try { + const res = await fetch(getApiUrl('/api/social/post'), { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(payload) + }); + + if (!res.ok) { + const errText = await res.text(); + throw new Error(errText); + } + + results.push({ index: i, success: true }); + } catch (e) { + results.push({ index: i, success: false, error: e.message }); + } + + setProgress({ current: i + 1, total, results: [...results] }); + } + + setDone(true); + setScheduling(false); + }; + + const successCount = progress.results.filter(r => r.success).length; + const failCount = progress.results.filter(r => !r.success).length; + + return ( +
+
+ + + {/* Header */} +
+
+ +
+
+

Programar Semana

+

{clips?.length || 0} clips · 1 por día

+
+
+ + {!uploadPostKey && ( +
+ +
Configura tu API Key de Upload-Post en Settings primero.
+
+ )} + + {/* Time + Timezone */} +
+
+ + setTime(e.target.value)} + disabled={scheduling} + className="w-full bg-black/40 border border-white/10 rounded-lg p-3 text-sm text-white focus:outline-none focus:border-purple-500/50 [color-scheme:dark]" + /> +
+
+ + +
+
+ + {/* Start day offset */} +
+ Empezar desde +
+ + + {(() => { + const d = new Date(); + d.setDate(d.getDate() + startOffset); + return `${getDayLabel(d)} ${formatDate(d)}`; + })()} + + +
+
+ + {/* Calendar grid */} +
+ {schedule.map(({ clip, index, date }) => ( +
+
+
{getDayLabel(date)}
+
{date.getDate()}
+
{MONTHS[date.getMonth()]}
+
+ +
+
+ Clip {index + 1} +
+
+ {clip.video_title_for_youtube_short || 'Viral Short'} +
+
+ {time}h · {TIMEZONES.find(t => t.value === timezone)?.label || timezone} +
+
+ +
+ {progress.results[index]?.success === true && ( + + )} + {progress.results[index]?.success === false && ( + + )} + {scheduling && progress.current === index && ( + + )} + {!scheduling && progress.results[index] === undefined && ( +
+ )} +
+
+ ))} +
+ + {/* Platforms */} +
+ +
+ + + +
+
+ + {/* Progress bar */} + {(scheduling || done) && ( +
+
+ {scheduling ? 'Programando...' : 'Completado'} + {progress.current}/{progress.total} +
+
+
0 ? 'bg-yellow-500' : 'bg-purple-500'}`} + style={{ width: `${(progress.current / progress.total) * 100}%` }} + /> +
+ {done && ( +
+ {failCount === 0 ? ( + Todos los clips programados correctamente + ) : ( + {successCount} programados, {failCount} fallidos + )} +
+ )} +
+ )} + + {/* Actions */} +
+ + {!done ? ( + + ) : ( + + + Ver Calendario + + )} +
+
+
+ ); +}