From 6f9c01e2c68cc167df482b392b1871103a3b7b2d Mon Sep 17 00:00:00 2001 From: "juancarlos.cavero" Date: Sat, 29 Aug 2026 02:53:32 +0200 Subject: [PATCH] feat(dashboard): show each clip's score and lead with the best one MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The detail pass has always returned a predicted_score per clip and the dashboard threw it away, rendering the clips in transcript order. That buries the strongest clip wherever it happens to fall in the video, and the first card is the one people actually watch, publish and judge the product by. The cards are now ordered by score, and each one carries its number. The ORIGINAL array position is what still travels down as `index`: it is the clip's identity in clip_index on /api/subtitle, /api/edit and publishing, in the clip-N.mp4 download name and in the saved per-clip project state. Sorting the array itself would have repointed all of that at the wrong clip, silently. So the badge keeps saying "Clip 4" at the top of the list rather than "Clip 1" — the number identifies the file you download, the position tells you what to post first. Ties and clips with no score keep transcript order. Claude-Session: https://claude.ai/code/session_01KeQYCfUX2E9Q2fDgZMKEaJ --- dashboard/src/App.jsx | 25 +++++++++++++++++++++++-- dashboard/src/components/ResultCard.jsx | 15 +++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/dashboard/src/App.jsx b/dashboard/src/App.jsx index b8b3d3f..46de13f 100644 --- a/dashboard/src/App.jsx +++ b/dashboard/src/App.jsx @@ -1,4 +1,4 @@ -import React, { useState, useEffect, useRef } from 'react'; +import React, { useState, useEffect, useRef, useMemo } from 'react'; import { Upload, Sparkles, Youtube, Instagram, Share2, ChevronDown, Check, Activity, LayoutDashboard, Settings, Plus, History, X, Terminal, Shield, LayoutGrid, Image, Globe, RotateCcw, Calendar, AlertTriangle, KeyRound, Bot, Users, Smartphone, ExternalLink, Copy, CheckCircle2, Mail, Loader2, Download, Menu } from 'lucide-react'; import KeyInput from './components/KeyInput'; import MediaInput from './components/MediaInput'; @@ -242,6 +242,27 @@ function App() { const [jobId, setJobId] = useState(null); const [status, setStatus] = useState('idle'); // idle, processing, complete, error const [results, setResults] = useState(null); + // Best clips first. The backend hands them back in transcript order, which + // buries the strongest one wherever it happens to fall in the video — and + // the first card is the one people actually watch and publish. + // + // The ORIGINAL array position travels with each clip and is what gets passed + // down as `index`: it is the clip's identity everywhere else (clip_index on + // /api/subtitle, /api/edit and publishing, the clip-N.mp4 download name, the + // saved per-clip project state). Sorting the array itself would silently + // repoint all of that at the wrong clip. + const rankedClips = useMemo(() => { + const clips = results?.clips; + if (!Array.isArray(clips)) return []; + return clips + .map((clip, index) => ({ clip, index })) + .sort((a, b) => { + const sa = Number.isFinite(a.clip?.predicted_score) ? a.clip.predicted_score : -1; + const sb = Number.isFinite(b.clip?.predicted_score) ? b.clip.predicted_score : -1; + // Ties (and clips with no score at all) keep transcript order. + return sb - sa || a.index - b.index; + }); + }, [results]); // Bulk subtitles: apply one style to every clip of the job (triggered from // within a clip's subtitle modal via "apply to all"). const [bulkSub, setBulkSub] = useState({ running: false, current: 0, total: 0, errors: 0 }); @@ -1845,7 +1866,7 @@ function App() {
{results && results.clips && results.clips.length > 0 ? (
- {results.clips.map((clip, i) => ( + {rankedClips.map(({ clip, index: i }) => (
+ {/* Stays the clip's own number, not its rank: the cards are + ordered by score, but this is what the downloaded file + is called (clip-N.mp4) and what every api call indexes. */} Clip {index + 1} + {Number.isFinite(clip.predicted_score) && ( + = 80 ? 'text-ok' + : clip.predicted_score >= 65 ? 'text-brass' + : 'text-muted' + }`} + title="how viral the ai predicts this clip is, 0-100" + > + {clip.predicted_score} + + )}
{/* Auto Edit Overlay if Processing */}