CenaForge: primeira versão pública
Gerador de vídeos narrativos (Godot + FFmpeg), painel Next.js, serviço de voz, Clipador de lives e Publicador para YouTube, TikTok e Instagram. Inclui a leitura das visualizações dos posts para o Dashboard e o botão "Publicar no <rede>" nos cartões das publicações. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,214 @@
|
||||
"use client";
|
||||
// "Aprovar para publicar" na página do episódio: abre um diálogo com a prévia do vídeo final, título e
|
||||
// legenda editáveis e os canais de publicação (com as redes) que vão receber. POST /api/episodes/[id]/approve
|
||||
// cria os jobs já aprovados; DELETE desfaz (cancela o que ainda não saiu). Depois, router.refresh().
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState, useTransition } from "react";
|
||||
import type { EpisodeApproval } from "@/lib/publishing";
|
||||
import { askConfirm } from "./confirm-dialog";
|
||||
import { Dialog } from "./dialog";
|
||||
import { AlertIcon, CheckIcon, PublishIcon, UndoIcon, UsersIcon } from "./icons";
|
||||
import { PLATFORM_META } from "./platforms";
|
||||
import { approveEpisode, unapproveEpisode } from "./publishing-client";
|
||||
import { PublishChips, TextLink } from "./publishing-ui";
|
||||
import { Badge, Button, Feedback, Field, Input, Select, Spinner, Textarea, cx, fileUrl, formatDate } from "./ui";
|
||||
|
||||
const TITLE_MAX = 100;
|
||||
const CAPTION_MAX = 2200;
|
||||
|
||||
const NETWORK_REASON: Record<string, string> = {
|
||||
disconnected: "não conectado",
|
||||
connecting: "conectando",
|
||||
needs_login: "precisa entrar de novo (sai depois que você entrar)",
|
||||
expired: "conexão vencida (sai depois que você conectar de novo)",
|
||||
error: "com erro na conexão",
|
||||
};
|
||||
|
||||
export function EpisodeApprove({ episodeId, approval, label }: {
|
||||
episodeId: number;
|
||||
approval: EpisodeApproval;
|
||||
/** Como a interface chama o vídeo: "ep01" ou "vídeo". */
|
||||
label: string;
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const [, startTransition] = useTransition();
|
||||
const [open, setOpen] = useState(false);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [message, setMessage] = useState<{ ok: boolean; text: string } | null>(null);
|
||||
const jobs = approval.jobs.filter((j) => j.status !== "canceled");
|
||||
const hasFinal = approval.renders.length > 0;
|
||||
const approved = approval.approvedAt !== null;
|
||||
|
||||
async function undo() {
|
||||
const ok = await askConfirm({
|
||||
title: "Desfazer a aprovação?",
|
||||
message: "O que ainda não saiu é cancelado. O que já foi publicado continua nas redes.",
|
||||
confirmLabel: "Desfazer aprovação", cancelLabel: "Voltar", tone: "danger",
|
||||
});
|
||||
if (!ok) return;
|
||||
setBusy(true);
|
||||
const r = await unapproveEpisode(episodeId);
|
||||
setBusy(false);
|
||||
setMessage(r.ok ? { ok: true, text: "Aprovação desfeita." } : { ok: false, text: r.error });
|
||||
startTransition(() => router.refresh());
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="grid gap-3 rounded-card border border-line bg-sunken/30 p-4">
|
||||
<div className="flex flex-wrap items-center justify-between gap-2">
|
||||
<h3 className="text-eyebrow font-semibold text-fg-subtle uppercase">Publicar nas redes</h3>
|
||||
{approved && <Badge tone="success" dot={false}><CheckIcon size={13} />Aprovado</Badge>}
|
||||
</div>
|
||||
|
||||
{approved ? (
|
||||
<>
|
||||
<p className="text-xs text-fg-muted">Aprovado em {formatDate(approval.approvedAt)}.</p>
|
||||
<PublishChips jobs={jobs} showAccount={new Set(jobs.map((j) => j.accountId)).size > 1}
|
||||
emptyText="Nenhuma rede vai receber: nenhum canal ligado a esta história tem rede conectada." />
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<Button variant="secondary" size="sm" onClick={() => { setMessage(null); setOpen(true); }} disabled={busy}>
|
||||
<PublishIcon size={15} />Mudar e aprovar de novo
|
||||
</Button>
|
||||
<Button variant="ghost" size="sm" onClick={() => void undo()} disabled={busy}>
|
||||
{busy ? <Spinner className="size-3.5" /> : <UndoIcon size={15} />}Desfazer aprovação
|
||||
</Button>
|
||||
</div>
|
||||
<TextLink href="/publishing">Acompanhar em Publicações</TextLink>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<p className="text-xs leading-relaxed text-fg-muted">
|
||||
{hasFinal
|
||||
? `Confira o vídeo final, o título e a legenda, e libere o ${label} para os canais de publicação desta história.`
|
||||
: "Precisa de um vídeo final antes: use “Renderizar final (1080×1920)” ou monte o vídeo."}
|
||||
</p>
|
||||
<div>
|
||||
<Button size="sm" onClick={() => { setMessage(null); setOpen(true); }} disabled={!hasFinal}
|
||||
aria-describedby={hasFinal ? undefined : `sem-final-${episodeId}`}>
|
||||
<PublishIcon size={15} />Aprovar para publicar
|
||||
</Button>
|
||||
{!hasFinal && <span id={`sem-final-${episodeId}`} className="sr-only">Indisponível: falta o vídeo final.</span>}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
<div aria-live="polite" className="empty:hidden">{message && <Feedback ok={message.ok}>{message.text}</Feedback>}</div>
|
||||
|
||||
{open && (
|
||||
<ApproveDialog episodeId={episodeId} approval={approval} label={label} onClose={() => setOpen(false)}
|
||||
onDone={(text) => { setOpen(false); setMessage({ ok: true, text }); startTransition(() => router.refresh()); }} />
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function ApproveDialog({ episodeId, approval, label, onClose, onDone }: {
|
||||
episodeId: number; approval: EpisodeApproval; label: string; onClose: () => void; onDone: (text: string) => void;
|
||||
}) {
|
||||
const [renderId, setRenderId] = useState(() => approval.renderId && approval.renders.some((r) => r.id === approval.renderId)
|
||||
? approval.renderId : approval.renders[0]?.id ?? 0);
|
||||
const [title, setTitle] = useState(approval.title);
|
||||
const [caption, setCaption] = useState(approval.caption);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const render = approval.renders.find((r) => r.id === renderId);
|
||||
const receiving = approval.targets.reduce((n, t) => n + t.networks.filter((x) => x.willReceive).length, 0);
|
||||
|
||||
async function submit() {
|
||||
if (!title.trim()) { setError("Escreva um título."); return; }
|
||||
if (!render) { setError("Escolha o vídeo final."); return; }
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
const r = await approveEpisode(episodeId, { renderId: render.id, title: title.trim(), caption: caption.trim() });
|
||||
setBusy(false);
|
||||
if (!r.ok) { setError(r.error); return; }
|
||||
onDone(receiving === 1 ? "Aprovado: 1 rede vai receber." : `Aprovado: ${receiving} redes vão receber.`);
|
||||
}
|
||||
|
||||
return (
|
||||
<Dialog open onClose={onClose} size="lg" eyebrow={<><PublishIcon size={14} />Publicar nas redes</>}
|
||||
title={`Aprovar o ${label} para publicar`}
|
||||
description="Depois de aprovar, cada canal publica no horário que ele usa (na hora ou no próximo horário bom)."
|
||||
footer={<>
|
||||
<Button variant="secondary" onClick={onClose}>Voltar</Button>
|
||||
<Button onClick={() => void submit()} disabled={busy || receiving === 0}>
|
||||
{busy ? <><Spinner />Aprovando…</> : <><CheckIcon size={16} />Aprovar para publicar</>}
|
||||
</Button>
|
||||
</>}>
|
||||
<div className="grid gap-6 md:grid-cols-[minmax(0,14rem)_minmax(0,1fr)]">
|
||||
<div className="grid content-start gap-3">
|
||||
<div className="aspect-9/16 w-full overflow-hidden rounded-control border border-line-strong bg-sunken">
|
||||
{render
|
||||
? <video key={render.mp4} controls preload="metadata" src={fileUrl(render.mp4)} aria-label="Prévia do vídeo final" className="size-full object-contain" />
|
||||
: <p className="grid size-full place-items-center p-4 text-center text-xs text-fg-subtle">Sem vídeo final.</p>}
|
||||
</div>
|
||||
{approval.renders.length > 1 && (
|
||||
<Field label="Vídeo final">
|
||||
<Select value={renderId} onChange={(e) => setRenderId(Number(e.target.value))}>
|
||||
{approval.renders.map((r) => (
|
||||
<option key={r.id} value={r.id}>{r.profile === "documentary" ? "Montagem" : "Final"} · {formatDate(r.finishedAt)}</option>
|
||||
))}
|
||||
</Select>
|
||||
</Field>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="grid content-start gap-5">
|
||||
<Field label="Título" hint={<Counter value={title.length} max={TITLE_MAX} note="O YouTube usa o título; TikTok e Instagram usam a legenda." />}>
|
||||
<Input value={title} onChange={(e) => setTitle(e.target.value)} maxLength={TITLE_MAX} required />
|
||||
</Field>
|
||||
<Field label="Legenda" hint={<Counter value={caption.length} max={CAPTION_MAX} note="Descrição do post, com as hashtags." />}>
|
||||
<Textarea value={caption} onChange={(e) => setCaption(e.target.value)} maxLength={CAPTION_MAX} rows={5} />
|
||||
</Field>
|
||||
|
||||
<section aria-labelledby="quem-recebe" className="grid gap-2">
|
||||
<h3 id="quem-recebe" className="text-[0.8125rem] font-medium text-fg-muted">Quem vai receber</h3>
|
||||
{approval.targets.length === 0 ? (
|
||||
<p className="flex gap-2 rounded-control border border-warning/30 bg-warning-soft px-3 py-2 text-[0.8125rem] leading-relaxed text-warning">
|
||||
<AlertIcon size={15} className="mt-0.5" />
|
||||
<span>Nenhum canal de publicação tem esta história. Ligue a história a um canal em <TextLink href="/accounts">Canais de publicação</TextLink>.</span>
|
||||
</p>
|
||||
) : (
|
||||
<ul className="grid divide-y divide-line rounded-control border border-line">
|
||||
{approval.targets.map((t) => (
|
||||
<li key={t.accountId} className="grid gap-2 px-3.5 py-2.5">
|
||||
<span className="flex items-center gap-2 text-sm font-medium text-fg"><UsersIcon size={15} className="text-fg-subtle" />{t.name}</span>
|
||||
<ul className="grid gap-1 pl-6">
|
||||
{(["youtube", "tiktok", "instagram"] as const).map((p) => {
|
||||
const n = t.networks.find((x) => x.platform === p);
|
||||
const Icon = PLATFORM_META[p].icon;
|
||||
const reason = !n ? "não conectado" : n.willReceive ? null : !n.enabled ? "pausado neste canal" : NETWORK_REASON[n.status] ?? "não recebe";
|
||||
return (
|
||||
<li key={p} className={cx("flex flex-wrap items-center gap-x-2 text-[0.8125rem]", reason ? "text-fg-subtle" : "text-fg")}>
|
||||
<Icon size={14} />
|
||||
<span>{PLATFORM_META[p].label}:</span>
|
||||
{reason ? <span>não recebe ({reason})</span>
|
||||
: <span className="inline-flex items-center gap-1 font-medium text-success"><CheckIcon size={13} />vai receber</span>}
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
{approval.targets.length > 0 && receiving === 0 && (
|
||||
<p className="text-xs leading-relaxed text-warning">Nenhuma rede conectada para receber. Conecte em <TextLink href="/accounts">Canais de publicação</TextLink>.</p>
|
||||
)}
|
||||
</section>
|
||||
|
||||
<div aria-live="assertive" className="empty:hidden">{error && <Feedback ok={false}>{error}</Feedback>}</div>
|
||||
</div>
|
||||
</div>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
function Counter({ value, max, note }: { value: number; max: number; note: string }) {
|
||||
return (
|
||||
<span className="flex flex-wrap justify-between gap-x-3">
|
||||
<span>{note}</span>
|
||||
<span className={cx("tabular-nums", value > max * 0.9 && "text-warning")}>{value}/{max}</span>
|
||||
</span>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user