Clipador: subpáginas, jogos, idioma por canal e juiz com Gemini e IA reserva
- Clipador em subpáginas (Cortes, Sessões, Fontes, Jogos, Ajustes) com moldura comum, lista + diálogo dos cortes e submenu na barra lateral. - Perfis de jogo (o que a IA sabe de cada jogo), parar pausa o monitor e idioma por fonte e por canal de publicação (migração v9: accounts.language). - Juiz: Gemini CLI como terceiro provedor e IA reserva por chamada — se a IA escolhida cair por cota, login, chave ou rede, a próxima da ordem de Configurações → IA responde (com pausa da que caiu). Lê data/ai/settings.json e o cofre data/ai/vault.bin (DPAPI) escritos pelo painel; contrato em doc/ia.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,192 @@
|
||||
"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>
|
||||
|
||||
{editable && <TrimControl clip={clip} pending={pending} run={run} />}
|
||||
|
||||
{clip.transcript && (
|
||||
<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>
|
||||
);
|
||||
}
|
||||
|
||||
/** 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>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user