Merge fix/ui-model-badge-clip-preview: clip card redesign + social connect gating

This commit is contained in:
juancarlos.cavero 2026-07-18 23:38:14 +02:00
commit d5f2767d70
3 changed files with 137 additions and 45 deletions

View file

@ -1367,6 +1367,8 @@ function App() {
geminiApiKey={apiKey} geminiApiKey={apiKey}
elevenLabsKey={elevenLabsKey} elevenLabsKey={elevenLabsKey}
isManaged={isManaged} isManaged={isManaged}
connectedPlatforms={(userProfiles.find((p) => p.username === uploadUserId) || userProfiles[0])?.connected ?? null}
onConnectSocials={isManaged ? handleConnectSocials : null}
onPlay={(time) => handleClipPlay(time)} onPlay={(time) => handleClipPlay(time)}
onPause={handleClipPause} onPause={handleClipPause}
onBulkSubtitle={handleBulkSubtitles} onBulkSubtitle={handleBulkSubtitles}

View file

@ -137,7 +137,7 @@ const ProcessingAnimation = ({ media, isComplete, syncedTime, isSyncedPlaying, s
{!isSyncedPlaying && !isComplete && ( {!isSyncedPlaying && !isComplete && (
<div className="absolute top-4 right-4 z-30 flex items-center gap-2 px-3 py-1.5 bg-black/70 rounded-full readout"> <div className="absolute top-4 right-4 z-30 flex items-center gap-2 px-3 py-1.5 bg-black/70 rounded-full readout">
AI_MODEL: GEMINI-2.5-PRO VIRAL_DETECTION: ACTIVE
</div> </div>
)} )}

View file

@ -1,5 +1,5 @@
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect } from 'react';
import { Download, Share2, Instagram, Youtube, Video, AlertCircle, Loader2, Copy, Check, Wand2, Type, Calendar, Languages } from 'lucide-react'; import { Download, Share2, Instagram, Youtube, Video, AlertCircle, Loader2, Copy, Check, Wand2, Type, Calendar, Languages, FileText, Link2 } from 'lucide-react';
import { getApiUrl } from '../config'; import { getApiUrl } from '../config';
import { apiFetch } from '../lib/api'; import { apiFetch } from '../lib/api';
import SubtitleModal from './SubtitleModal'; import SubtitleModal from './SubtitleModal';
@ -9,7 +9,7 @@ import Modal from './ui/Modal';
import SegmentedControl from './ui/SegmentedControl'; import SegmentedControl from './ui/SegmentedControl';
import { renderInBrowser } from '../lib/renderInBrowser'; import { renderInBrowser } from '../lib/renderInBrowser';
const QUIET_BTN = 'group flex items-center justify-center gap-2 py-2 px-2 rounded-input border border-rule hover:bg-paper3 text-xs lowercase text-ink2 transition-colors disabled:opacity-45 disabled:cursor-not-allowed'; const QUIET_BTN = 'group flex flex-col items-center justify-center gap-1 py-2 px-1 rounded-input border border-rule hover:bg-paper3 text-[11px] lowercase text-ink2 whitespace-nowrap transition-colors disabled:opacity-45 disabled:cursor-not-allowed';
const PLATFORM_OPTIONS = [ const PLATFORM_OPTIONS = [
{ value: 'tiktok', label: 'tiktok', icon: <Video size={16} /> }, { value: 'tiktok', label: 'tiktok', icon: <Video size={16} /> },
@ -23,8 +23,9 @@ function formatDuration(clip) {
return `${String(Math.floor(secs / 60)).padStart(2, '0')}:${String(secs % 60).padStart(2, '0')}`; return `${String(Math.floor(secs / 60)).padStart(2, '0')}:${String(secs % 60).padStart(2, '0')}`;
} }
export default function ResultCard({ clip, index, jobId, durableUrl, uploadPostKey, uploadUserId, geminiApiKey, elevenLabsKey, isManaged, onPlay, onPause, onBulkSubtitle, clipCount = 1, bulkProgress, initialState = null, onStateChange }) { export default function ResultCard({ clip, index, jobId, durableUrl, uploadPostKey, uploadUserId, geminiApiKey, elevenLabsKey, isManaged, onPlay, onPause, onBulkSubtitle, clipCount = 1, bulkProgress, initialState = null, onStateChange, connectedPlatforms = null, onConnectSocials }) {
const [showModal, setShowModal] = useState(false); const [showModal, setShowModal] = useState(false);
const [showDescModal, setShowDescModal] = useState(false);
const [showSubtitleModal, setShowSubtitleModal] = useState(false); const [showSubtitleModal, setShowSubtitleModal] = useState(false);
const videoRef = React.useRef(null); const videoRef = React.useRef(null);
// Pristine base clip (no burned subtitles/hook), stable regardless of how // Pristine base clip (no burned subtitles/hook), stable regardless of how
@ -44,6 +45,7 @@ export default function ResultCard({ clip, index, jobId, durableUrl, uploadPostK
// A reopened project seeds it from the persisted project state. // A reopened project seeds it from the persisted project state.
const [serverVideoFile, setServerVideoFile] = useState(initialState?.server_file || (clip.video_url || '').split('/').pop()); const [serverVideoFile, setServerVideoFile] = useState(initialState?.server_file || (clip.video_url || '').split('/').pop());
const [videoErrored, setVideoErrored] = useState(false); const [videoErrored, setVideoErrored] = useState(false);
const [resolution, setResolution] = useState(null);
// If the local video failed and a durable R2 URL is (now) available, use it. // If the local video failed and a durable R2 URL is (now) available, use it.
// Handles the race where the video errors before the durable URL has loaded. // Handles the race where the video errors before the durable URL has loaded.
@ -132,6 +134,20 @@ export default function ResultCard({ clip, index, jobId, durableUrl, uploadPostK
.catch(() => {}); .catch(() => {});
}, [jobId, index]); }, [jobId, index]);
// Which platforms the selected profile actually has linked. `null` means
// unknown (profile list not loaded) — in that case nothing is gated.
const knownConnections = Array.isArray(connectedPlatforms);
const noAccountsConnected = knownConnections && connectedPlatforms.length === 0;
const platformOptions = knownConnections
? PLATFORM_OPTIONS.map((o) => (connectedPlatforms.includes(o.value) ? o : { ...o, disabled: true, hint: 'not connected' }))
: PLATFORM_OPTIONS;
const handleConnectAccounts = () => {
setShowModal(false);
if (onConnectSocials) onConnectSocials();
else window.open('https://app.upload-post.com', '_blank', 'noopener');
};
// Initialize/Reset form when modal opens // Initialize/Reset form when modal opens
useEffect(() => { useEffect(() => {
if (showModal) { if (showModal) {
@ -140,6 +156,14 @@ export default function ResultCard({ clip, index, jobId, durableUrl, uploadPostK
setIsScheduling(false); setIsScheduling(false);
setScheduleDate(""); setScheduleDate("");
setPostResult(null); setPostResult(null);
// Only preselect platforms the profile can actually publish to.
if (knownConnections) {
setPlatforms({
tiktok: connectedPlatforms.includes('tiktok'),
instagram: connectedPlatforms.includes('instagram'),
youtube: connectedPlatforms.includes('youtube'),
});
}
} }
}, [showModal, clip]); }, [showModal, clip]);
@ -440,6 +464,11 @@ export default function ResultCard({ clip, index, jobId, durableUrl, uploadPostK
return; return;
} }
if (noAccountsConnected) {
setPostResult({ success: false, msg: "Connect a social account first." });
return;
}
const selectedPlatforms = Object.keys(platforms).filter(k => platforms[k]); const selectedPlatforms = Object.keys(platforms).filter(k => platforms[k]);
if (selectedPlatforms.length === 0) { if (selectedPlatforms.length === 0) {
setPostResult({ success: false, msg: "Select at least one platform." }); setPostResult({ success: false, msg: "Select at least one platform." });
@ -504,15 +533,18 @@ export default function ResultCard({ clip, index, jobId, durableUrl, uploadPostK
const durationReadout = formatDuration(clip); const durationReadout = formatDuration(clip);
return ( return (
<div className="card overflow-hidden flex flex-col md:flex-row group hover:border-rule2 transition-colors animate-fade min-h-[300px] h-auto" style={{ animationDelay: `${index * 0.1}s` }}> <div className="card overflow-hidden flex flex-col md:flex-row group hover:border-rule2 transition-colors animate-fade md:min-h-[420px]" style={{ animationDelay: `${index * 0.1}s` }}>
{/* Left: Video Preview (Responsive Width) */} {/* Left: Video Preview — 9:16 column matching the fixed card height */}
<div className="w-full md:w-[180px] lg:w-[200px] bg-black relative shrink-0 aspect-[9/16] md:aspect-auto group/video"> <div className="w-full md:w-[236px] bg-black relative shrink-0 aspect-[9/16] md:aspect-auto group/video">
<video <video
ref={videoRef} ref={videoRef}
src={currentVideoUrl} src={currentVideoUrl}
controls controls
className="w-full h-full object-cover" className="w-full h-full object-contain"
playsInline playsInline
onLoadedMetadata={(e) => {
if (e.target.videoWidth) setResolution(`${e.target.videoWidth}×${e.target.videoHeight}`);
}}
onError={() => { onError={() => {
// Local /videos/ file gone (e.g. cleaned up after a reload) → // Local /videos/ file gone (e.g. cleaned up after a reload) →
// fall back to the durable R2 copy for managed users. If the // fall back to the durable R2 copy for managed users. If the
@ -556,17 +588,19 @@ export default function ResultCard({ clip, index, jobId, durableUrl, uploadPostK
</h3> </h3>
<div className="flex flex-wrap gap-1.5"> <div className="flex flex-wrap gap-1.5">
{durationReadout && <span className="readout bg-paper3 px-2 py-0.5 rounded-full shrink-0">{durationReadout}</span>} {durationReadout && <span className="readout bg-paper3 px-2 py-0.5 rounded-full shrink-0">{durationReadout}</span>}
{resolution && <span className="readout bg-paper3 px-2 py-0.5 rounded-full shrink-0">{resolution}</span>}
<span className="readout bg-paper3 px-2 py-0.5 rounded-full shrink-0">#shorts</span> <span className="readout bg-paper3 px-2 py-0.5 rounded-full shrink-0">#shorts</span>
<span className="readout bg-paper3 px-2 py-0.5 rounded-full shrink-0">#viral</span> <span className="readout bg-paper3 px-2 py-0.5 rounded-full shrink-0">#viral</span>
</div> </div>
</div> </div>
{/* Scrollable Descriptions Area */} {/* Descriptions (compact) — full text lives in the modal */}
<div className="flex-1 overflow-y-auto custom-scrollbar space-y-3 pr-2 mb-4"> <div className="flex-1 min-h-0 space-y-2 mb-4">
{/* YouTube */} <div className="bg-paper rounded-input px-3 py-2 border border-rule flex items-center gap-2 min-w-0">
<div className="bg-paper rounded-input p-3 border border-rule"> <span className="eyebrow shrink-0">YOUTUBE</span>
<div className="flex items-center justify-between gap-2 mb-1.5"> <p className="text-xs text-ink2 truncate flex-1 min-w-0">
<span className="eyebrow truncate">YOUTUBE</span> {clip.video_title_for_youtube_short || "Viral Short Video"}
</p>
<button <button
onClick={() => handleCopy('youtube', clip.video_title_for_youtube_short || "Viral Short Video")} onClick={() => handleCopy('youtube', clip.video_title_for_youtube_short || "Viral Short Video")}
aria-label="copy youtube title" aria-label="copy youtube title"
@ -575,15 +609,12 @@ export default function ResultCard({ clip, index, jobId, durableUrl, uploadPostK
{copied === 'youtube' ? <Check size={14} className="text-ok" /> : <Copy size={14} />} {copied === 'youtube' ? <Check size={14} className="text-ok" /> : <Copy size={14} />}
</button> </button>
</div> </div>
<p className="text-xs text-ink2 select-all break-words">
{clip.video_title_for_youtube_short || "Viral Short Video"}
</p>
</div>
{/* TikTok / IG */} <div className="bg-paper rounded-input px-3 py-2 border border-rule flex items-center gap-2 min-w-0">
<div className="bg-paper rounded-input p-3 border border-rule"> <span className="eyebrow shrink-0">TIKTOK · IG</span>
<div className="flex items-center justify-between gap-2 mb-1.5"> <p className="text-xs text-ink2 truncate flex-1 min-w-0">
<span className="eyebrow truncate">TIKTOK · IG</span> {clip.video_description_for_tiktok || clip.video_description_for_instagram}
</p>
<button <button
onClick={() => handleCopy('caption', clip.video_description_for_tiktok || clip.video_description_for_instagram)} onClick={() => handleCopy('caption', clip.video_description_for_tiktok || clip.video_description_for_instagram)}
aria-label="copy caption" aria-label="copy caption"
@ -592,10 +623,13 @@ export default function ResultCard({ clip, index, jobId, durableUrl, uploadPostK
{copied === 'caption' ? <Check size={14} className="text-ok" /> : <Copy size={14} />} {copied === 'caption' ? <Check size={14} className="text-ok" /> : <Copy size={14} />}
</button> </button>
</div> </div>
<p className="text-xs text-ink2 line-clamp-3 hover:line-clamp-none transition-all cursor-pointer select-all break-words">
{clip.video_description_for_tiktok || clip.video_description_for_instagram} <button
</p> onClick={() => setShowDescModal(true)}
</div> className="w-full flex items-center justify-center gap-2 py-2 rounded-input border border-dashed border-rule text-xs lowercase text-muted hover:text-brass hover:border-rule2 transition-colors"
>
<FileText size={14} /> view descriptions
</button>
</div> </div>
{/* Error Message */} {/* Error Message */}
@ -646,7 +680,7 @@ export default function ResultCard({ clip, index, jobId, durableUrl, uploadPostK
<button <button
onClick={() => setShowModal(true)} onClick={() => setShowModal(true)}
className="btn-primary py-2 px-2 text-xs" className="btn-primary flex-col gap-1 py-2 px-1 text-[11px] rounded-input whitespace-nowrap"
> >
<Share2 size={16} className="shrink-0" /> post <Share2 size={16} className="shrink-0" /> post
</button> </button>
@ -678,6 +712,49 @@ export default function ResultCard({ clip, index, jobId, durableUrl, uploadPostK
</div> </div>
</div> </div>
{/* Descriptions Modal */}
<Modal
isOpen={showDescModal}
onClose={() => setShowDescModal(false)}
eyebrow="GENERATED COPY"
title="descriptions"
size="md"
>
<div className="space-y-4">
<div>
<div className="flex items-center justify-between gap-2 mb-1.5">
<label className="eyebrow">YOUTUBE TITLE</label>
<button
onClick={() => handleCopy('youtube', clip.video_title_for_youtube_short || "Viral Short Video")}
aria-label="copy youtube title"
className="p-1 rounded-full text-muted hover:text-brass transition-colors shrink-0"
>
{copied === 'youtube' ? <Check size={14} className="text-ok" /> : <Copy size={14} />}
</button>
</div>
<p className="text-sm text-ink2 select-all break-words bg-paper rounded-input p-3 border border-rule">
{clip.video_title_for_youtube_short || "Viral Short Video"}
</p>
</div>
<div>
<div className="flex items-center justify-between gap-2 mb-1.5">
<label className="eyebrow">TIKTOK · IG CAPTION</label>
<button
onClick={() => handleCopy('caption', clip.video_description_for_tiktok || clip.video_description_for_instagram)}
aria-label="copy caption"
className="p-1 rounded-full text-muted hover:text-brass transition-colors shrink-0"
>
{copied === 'caption' ? <Check size={14} className="text-ok" /> : <Copy size={14} />}
</button>
</div>
<p className="text-sm text-ink2 select-all break-words bg-paper rounded-input p-3 border border-rule whitespace-pre-wrap">
{clip.video_description_for_tiktok || clip.video_description_for_instagram}
</p>
</div>
</div>
</Modal>
{/* Post Modal */} {/* Post Modal */}
<Modal <Modal
isOpen={showModal} isOpen={showModal}
@ -686,6 +763,11 @@ export default function ResultCard({ clip, index, jobId, durableUrl, uploadPostK
title="post clip" title="post clip"
size="md" size="md"
footer={ footer={
noAccountsConnected ? (
<button onClick={handleConnectAccounts} className="btn-primary w-full">
<Link2 size={16} /> connect accounts
</button>
) : (
<button <button
onClick={handlePost} onClick={handlePost}
disabled={posting || !canPost} disabled={posting || !canPost}
@ -693,6 +775,7 @@ export default function ResultCard({ clip, index, jobId, durableUrl, uploadPostK
> >
{posting ? <><Loader2 size={16} className="animate-spin" /> {isScheduling ? 'scheduling…' : 'publishing…'}</> : <><Share2 size={16} /> {isScheduling ? 'schedule post' : 'publish now'}</>} {posting ? <><Loader2 size={16} className="animate-spin" /> {isScheduling ? 'scheduling…' : 'publishing…'}</> : <><Share2 size={16} /> {isScheduling ? 'schedule post' : 'publish now'}</>}
</button> </button>
)
} }
> >
{!canPost && ( {!canPost && (
@ -702,6 +785,13 @@ export default function ResultCard({ clip, index, jobId, durableUrl, uploadPostK
</div> </div>
)} )}
{noAccountsConnected && (
<div className="mb-4 px-3 py-2 rounded-input text-xs text-warn bg-[color-mix(in_oklab,var(--color-warn)_10%,transparent)] flex items-start gap-2">
<AlertCircle size={14} className="mt-0.5 shrink-0" />
<div className="lowercase">no social accounts connected yet — link tiktok, instagram or youtube to publish this clip.</div>
</div>
)}
<div className="space-y-4"> <div className="space-y-4">
{/* Title & Description */} {/* Title & Description */}
<div> <div>
@ -759,7 +849,7 @@ export default function ResultCard({ clip, index, jobId, durableUrl, uploadPostK
<SegmentedControl <SegmentedControl
multi multi
columns={3} columns={3}
options={PLATFORM_OPTIONS} options={platformOptions}
value={Object.keys(platforms).filter(k => platforms[k])} value={Object.keys(platforms).filter(k => platforms[k])}
onChange={(arr) => setPlatforms({ onChange={(arr) => setPlatforms({
tiktok: arr.includes('tiktok'), tiktok: arr.includes('tiktok'),