Clipador em inglês (doc/clipador/IDIOMAS.md):
- Fonte en-US: analista, editor e varredura com prompts, glossário de chat e saída em inglês;
a mesma resposta traz o bloco `pt` (tradução para o painel, sem chamada extra).
- Fala do corte traduzida por frase (clips.translation_json, migração v13) e
POST /v1/clips/{id}/translate.
- caption.translation (só para desenvolver): português embaixo da legenda em inglês.
- Risada e gírias do chat em inglês na heurística (LMAO, LOL, 💀, 😭, no way, bruh...).
- Idioma do público → código do Whisper (en-US dava 422 no serviço de voz).
- Painel: bloco "Em português" no corte, análise/resumo em PT, título traduzido na lista,
coluna "Ao vivo" mostra a gravação ativa da fonte.
IA: monitor de uso do limite (ai-usage) e 4º provedor (Antigravity CLI).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
239 lines
13 KiB
TypeScript
239 lines
13 KiB
TypeScript
"use client";
|
||
// Modal de um corte: vídeo e sinais à esquerda; estado, publicação, veredito da IA, título/legenda, ajuste do trecho e
|
||
// transcrição à direita. No rodapé, anterior/próximo (percorre a lista filtrada, na ordem exibida; ← → no teclado
|
||
// fora de campos de texto), as ações da etapa e "Apagar". Aprovar ou rejeitar pula sozinho para o próximo corte
|
||
// (fluxo de decidir em sequência); sem próximo, fecha.
|
||
import { useEffect, useState } from "react";
|
||
import { CLIP_STATUS, SOURCE_LABEL, clipperCall, formatClock, formatDuration, languageLabel, useClipperAction, type Clip, type ClipperSession } from "./clipper-client";
|
||
import {
|
||
ChatSignals, ClipActions, ClipMedia, DeleteControl, FaceSignal, JudgeVerdict, TrimControl, situationLabel, type DeleteClip,
|
||
} from "./clipper-clip-parts";
|
||
import { Dialog } from "./dialog";
|
||
import { ArrowLeftIcon, ArrowRightIcon, CheckIcon, ClockIcon } from "./icons";
|
||
import type { PublishJob } from "./publishing-client";
|
||
import { PublishChips, TextLink } from "./publishing-ui";
|
||
import { Badge, Button, Feedback, Input, Spinner, Textarea, cx } from "./ui";
|
||
|
||
export function ClipDialog({ clip, name, session, position, onPrev, onNext, onClose, onChanged, publishJobs, onPublished, deleting, onDelete }: {
|
||
clip: Clip;
|
||
name: string;
|
||
session: ClipperSession | undefined;
|
||
/** Posição na lista filtrada (1-based) e total; null = o corte não está mais na lista exibida. */
|
||
position: { index: number; total: number } | null;
|
||
/** null = não há anterior/próximo. */
|
||
onPrev: (() => void) | null;
|
||
onNext: (() => void) | null;
|
||
onClose: () => void;
|
||
onChanged: () => void;
|
||
/** Jobs de publicação deste corte (etapa Aprovados); null = não lidos. */
|
||
publishJobs: PublishJob[] | null;
|
||
onPublished: () => void;
|
||
deleting: boolean;
|
||
onDelete: DeleteClip;
|
||
}) {
|
||
// ← → trocam de corte quando o foco não está num campo de texto (o vídeo tem as próprias teclas).
|
||
useEffect(() => {
|
||
const onKey = (e: KeyboardEvent) => {
|
||
if (e.defaultPrevented || e.altKey || e.ctrlKey || e.metaKey) return;
|
||
const t = e.target as HTMLElement | null;
|
||
if (t && (t.closest("input, textarea, select, video, [contenteditable=true]"))) return;
|
||
if (e.key === "ArrowLeft" && onPrev) { e.preventDefault(); onPrev(); }
|
||
if (e.key === "ArrowRight" && onNext) { e.preventDefault(); onNext(); }
|
||
};
|
||
document.addEventListener("keydown", onKey);
|
||
return () => document.removeEventListener("keydown", onKey);
|
||
}, [onPrev, onNext]);
|
||
|
||
const status = CLIP_STATUS[clip.status];
|
||
const situation = situationLabel(clip);
|
||
return (
|
||
<Dialog open onClose={onClose} size="lg" dismissOnBackdrop
|
||
eyebrow={<>Corte #{clip.id} · {name} · sessão #{clip.sessionId}</>}
|
||
title={clip.title || `Corte ${clip.id}`}
|
||
description={<span className="flex flex-wrap items-center gap-x-3 gap-y-1">
|
||
<Badge tone={status.tone} pulse={status.pulse}>{status.label}</Badge>
|
||
<span>{situation ?? SOURCE_LABEL[clip.source]}</span>
|
||
<span className="inline-flex items-center gap-1 tabular-nums"><ClockIcon size={13} />{formatDuration(clip.durationS)} · {formatClock(clip.startS)}–{formatClock(clip.endS)}</span>
|
||
{clip.aspect === "horizontal" && <span>horizontal 16:9</span>}
|
||
{session?.language && <span title="Idioma da live">{languageLabel(session.language)}</span>}
|
||
</span>}
|
||
footer={<ClipFooter key={clip.id} clip={clip} position={position} onPrev={onPrev} onNext={onNext} onClose={onClose}
|
||
onChanged={onChanged} publishJobs={publishJobs} onPublished={onPublished} deleting={deleting} onDelete={onDelete} />}>
|
||
<ClipBody key={clip.id} clip={clip} onChanged={onChanged} publishJobs={publishJobs} />
|
||
</Dialog>
|
||
);
|
||
}
|
||
|
||
/** Corpo do modal. `key` por corte: rascunho de título/legenda e versão do vídeo começam do zero a cada corte. */
|
||
function ClipBody({ clip, onChanged, publishJobs }: { clip: Clip; onChanged: () => void; publishJobs: PublishJob[] | null }) {
|
||
const { pending, message, run } = useClipperAction(onChanged);
|
||
const base = `clips/${clip.id}`;
|
||
const busy = clip.status === "candidate" || clip.status === "pending" || clip.status === "rendering";
|
||
const editable = !busy && clip.status !== "published";
|
||
|
||
// Rascunho de título e legenda: a consulta periódica não apaga o que está sendo digitado.
|
||
const [saved, setSaved] = useState({ title: clip.title, caption: clip.caption });
|
||
const [title, setTitle] = useState(clip.title);
|
||
const [caption, setCaption] = useState(clip.caption);
|
||
if (saved.title !== clip.title || saved.caption !== clip.caption) {
|
||
setSaved({ title: clip.title, caption: clip.caption });
|
||
if (title === saved.title) setTitle(clip.title);
|
||
if (caption === saved.caption) setCaption(clip.caption);
|
||
}
|
||
const textDirty = title !== clip.title || caption !== clip.caption;
|
||
|
||
// Versão do vídeo: muda quando um render termina (mesmo caminho de arquivo, conteúdo novo).
|
||
const [videoVersion, setVideoVersion] = useState(clip.updatedAt);
|
||
const [lastStatus, setLastStatus] = useState(clip.status);
|
||
if (lastStatus !== clip.status) {
|
||
setLastStatus(clip.status);
|
||
if (lastStatus === "candidate" || lastStatus === "pending" || lastStatus === "rendering") setVideoVersion(clip.updatedAt);
|
||
}
|
||
|
||
const showPublication = clip.status === "approved" || clip.status === "published";
|
||
|
||
return (
|
||
<div className="grid gap-6 md:grid-cols-[minmax(0,18rem)_minmax(0,1fr)]">
|
||
<div className="grid content-start gap-4">
|
||
<ClipMedia clip={clip} version={videoVersion} />
|
||
<ChatSignals clip={clip} />
|
||
<FaceSignal clip={clip} />
|
||
</div>
|
||
|
||
<div className="grid min-w-0 content-start gap-5">
|
||
{showPublication && (
|
||
<section aria-label="Publicação nas redes" className="grid gap-1.5">
|
||
<h3 className="text-eyebrow font-semibold text-fg-subtle uppercase">Publicação</h3>
|
||
{publishJobs
|
||
? <PublishChips jobs={publishJobs} showAccount={new Set(publishJobs.map((j) => j.accountId)).size > 1}
|
||
emptyText={<>Ainda não foi para nenhuma rede. Use “Publicar” abaixo para escolher o canal e as redes. <TextLink href="/publishing">Abrir Publicações</TextLink></>} />
|
||
: <p className="flex items-center gap-2 text-xs text-fg-subtle"><Spinner className="size-3.5" />Lendo o estado da publicação…</p>}
|
||
</section>
|
||
)}
|
||
|
||
<section aria-label="Veredito da IA" className="grid gap-3">
|
||
<JudgeVerdict clip={clip} />
|
||
</section>
|
||
|
||
{clip.status === "error" && clip.error && (
|
||
<p className="rounded-control border border-danger/30 bg-danger-soft px-3 py-2 font-mono text-xs break-words text-danger">{clip.error}</p>
|
||
)}
|
||
|
||
<form className="grid gap-3" onSubmit={(e) => {
|
||
e.preventDefault();
|
||
void run("text", () => clipperCall<Clip>(base, "PATCH", { title, caption }), "Título e legenda salvos.");
|
||
}}>
|
||
<label className="grid gap-1.5">
|
||
<span className="text-[0.8125rem] font-medium text-fg-muted">Título</span>
|
||
<Input value={title} onChange={(e) => setTitle(e.target.value)} maxLength={100} disabled={!editable} className="h-9" />
|
||
</label>
|
||
<label className="grid gap-1.5">
|
||
<span className="text-[0.8125rem] font-medium text-fg-muted">Legenda do post</span>
|
||
<Textarea value={caption} onChange={(e) => setCaption(e.target.value)} rows={3} maxLength={2200} disabled={!editable} className="text-[0.8125rem]" />
|
||
</label>
|
||
{textDirty && (
|
||
<div className="flex flex-wrap items-center gap-2">
|
||
<Button type="submit" variant="secondary" size="sm" disabled={pending !== null}>
|
||
{pending === "text" ? <Spinner className="size-3.5" /> : <CheckIcon size={15} />}Salvar texto
|
||
</Button>
|
||
<Button type="button" variant="ghost" size="sm" onClick={() => { setTitle(clip.title); setCaption(clip.caption); }}>Desfazer</Button>
|
||
</div>
|
||
)}
|
||
</form>
|
||
|
||
<Portuguese clip={clip} pending={pending} run={run} />
|
||
|
||
{editable && <TrimControl clip={clip} pending={pending} run={run} />}
|
||
|
||
{clip.transcript && !clip.translation?.lines.length && (
|
||
<details className="group rounded-control border border-line bg-sunken/30 px-3 py-2 text-[0.8125rem]">
|
||
<summary className="cursor-pointer text-fg-muted select-none hover:text-fg">Transcrição</summary>
|
||
<p className="mt-2 leading-relaxed text-fg-muted">{clip.transcript}</p>
|
||
</details>
|
||
)}
|
||
|
||
<div aria-live="polite" className="empty:hidden">{message && <Feedback ok={message.ok}>{message.text}</Feedback>}</div>
|
||
</div>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
/** Fonte em inglês (doc/clipador/IDIOMAS.md): o vídeo, o título e a legenda do post saem em inglês; aqui a equipe lê
|
||
* a tradução — título, legenda e a fala frase a frase. Some em sessão em português. */
|
||
function Portuguese({ clip, pending, run }: {
|
||
clip: Clip;
|
||
pending: string | null;
|
||
run: ReturnType<typeof useClipperAction>["run"];
|
||
}) {
|
||
const pt = clip.judge && "pt" in clip.judge ? clip.judge.pt : undefined;
|
||
const lines = clip.translation?.lines ?? [];
|
||
const english = (clip.language ?? "").toLowerCase().startsWith("en");
|
||
if (!english && !pt && !lines.length) return null;
|
||
const translate = () => run("translate", () => clipperCall<Clip>(`clips/${clip.id}/translate`, "POST"), "Fala traduzida.");
|
||
return (
|
||
<section aria-label="Tradução para o português" className="grid gap-2.5 rounded-control border border-info/25 bg-info-soft/30 px-3.5 py-3">
|
||
<p className="flex flex-wrap items-center gap-2 text-xs">
|
||
<span className="font-semibold text-info">Em português</span>
|
||
<span className="text-fg-subtle">só para entender — o vídeo, o título e a legenda do post saem em inglês</span>
|
||
</p>
|
||
{pt?.title && <p className="text-[0.875rem] font-medium text-fg">{pt.title}</p>}
|
||
{pt?.caption && <p className="text-[0.8125rem] leading-relaxed text-fg-muted">{pt.caption}</p>}
|
||
{lines.length > 0 ? (
|
||
<details className="text-[0.8125rem]">
|
||
<summary className="cursor-pointer text-fg-muted select-none hover:text-fg">O que ele fala ({lines.length} frases)</summary>
|
||
<ol className="mt-2 grid gap-2">
|
||
{lines.map((line, i) => (
|
||
<li key={i} className="grid grid-cols-[3.25rem_minmax(0,1fr)] gap-2">
|
||
<span className="pt-px font-mono text-[0.6875rem] text-fg-subtle tabular-nums">{formatClock(line.s - clip.startS)}</span>
|
||
<span className="grid gap-0.5">
|
||
<span className="text-fg">{line.pt}</span>
|
||
<span className="text-xs text-fg-subtle italic">{line.text}</span>
|
||
</span>
|
||
</li>
|
||
))}
|
||
</ol>
|
||
</details>
|
||
) : english && clip.transcript ? (
|
||
<Button type="button" variant="ghost" size="sm" className="justify-self-start" disabled={pending !== null} onClick={() => void translate()}>
|
||
{pending === "translate" && <Spinner className="size-3.5" />}Traduzir a fala
|
||
</Button>
|
||
) : null}
|
||
</section>
|
||
);
|
||
}
|
||
|
||
/** Rodapé: anterior/próximo à esquerda, ações da etapa no meio, apagar à direita. */
|
||
function ClipFooter({ clip, position, onPrev, onNext, onClose, onChanged, publishJobs, onPublished, deleting, onDelete }: {
|
||
clip: Clip; position: { index: number; total: number } | null; onPrev: (() => void) | null; onNext: (() => void) | null; onClose: () => void;
|
||
onChanged: () => void; publishJobs: PublishJob[] | null; onPublished: () => void; deleting: boolean; onDelete: DeleteClip;
|
||
}) {
|
||
const { pending, message, setMessage, run } = useClipperAction(onChanged);
|
||
const publish = publishJobs ? { jobs: publishJobs, onDone: (m: { ok: boolean; text: string }) => { setMessage(m); onPublished(); } } : null;
|
||
return (
|
||
<div className="grid w-full gap-2">
|
||
<div className="flex w-full flex-wrap items-center gap-x-3 gap-y-2">
|
||
<div className="flex items-center gap-1" role="group" aria-label="Navegar entre os cortes da lista">
|
||
<Button variant="ghost" size="sm" disabled={!onPrev} onClick={() => onPrev?.()} aria-label="Corte anterior (seta para a esquerda)" title="Anterior (←)">
|
||
<ArrowLeftIcon size={15} />
|
||
</Button>
|
||
<span className="min-w-14 text-center text-xs text-fg-subtle tabular-nums">{position ? `${position.index} de ${position.total}` : "fora da lista"}</span>
|
||
<Button variant="ghost" size="sm" disabled={!onNext} onClick={() => onNext?.()} aria-label="Próximo corte (seta para a direita)" title="Próximo (→)">
|
||
<ArrowRightIcon size={15} />
|
||
</Button>
|
||
</div>
|
||
<ClipActions clip={clip} pending={pending} run={run} publish={publish} className="mx-auto"
|
||
onDecided={() => { if (onNext) onNext(); else onClose(); }} />
|
||
<div className={cx("ml-auto", !onNext && "")}>
|
||
<DeleteControl clip={clip} deleting={deleting} disabled={pending !== null}
|
||
onDelete={async (c, confirmPublished) => {
|
||
const ok = await onDelete(c, confirmPublished);
|
||
if (ok) { if (onNext) onNext(); else if (onPrev) onPrev(); else onClose(); }
|
||
return ok;
|
||
}} />
|
||
</div>
|
||
</div>
|
||
<div aria-live="polite" className="empty:hidden">{message && <Feedback ok={message.ok}>{message.text}</Feedback>}</div>
|
||
</div>
|
||
);
|
||
}
|