"use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; import { api } from "@/lib/client"; import type { GitStatus } from "@/lib/git"; import type { PublishStep } from "@/lib/publish"; type Config = { push: boolean; pushAuth: string; deploy: boolean; deployUrl: string | null }; function defaultMessage(status: GitStatus): string { const n = status.changes.length; return n === 1 && status.changes[0].path.endsWith("blog-posts.json") ? "blog: update posts" : `blog: update posts (${n} files)`; } export default function PublishPanel({ status: initial, config }: { status: GitStatus; config: Config }) { const router = useRouter(); const [status, setStatus] = useState(initial); const [message, setMessage] = useState(() => defaultMessage(initial)); const [running, setRunning] = useState(false); const [result, setResult] = useState<{ ok: boolean; steps: PublishStep[] } | null>(null); if (!status.available) { return (
{status.error}
Branch {status.branch}
{status.ahead !== undefined && (
<>
{" "}· {status.ahead} ahead / {status.behind} behind upstream (as of last fetch)
>
)}
. Only data/blog-posts.json and public/img/blog/ are committed.
No uncommitted blog changes.{ahead > 0 && ` ${ahead} commit(s) waiting to be pushed.`}
) : (| {c.code} | {c.path} |
{status.diffStat}}
commit → {config.push ? `push (${config.pushAuth})` : "push disabled (GIT_PUSH=false)"} →{" "} {config.deploy ? `trigger redeploy at ${config.deployUrl}` : "redeploy trigger not configured"}
{result.steps.map((s) => `[${s.status}] ${s.step}${s.output ? `\n${s.output}` : ""}`).join("\n\n")}
>
)}
>
);
}