"use client"; import { useState, useTransition } from "react"; import { moveArticleAction, publishArticleAction, setArticleAudienceAction, unpublishArticleAction, type ArticlesActionResult, } from "../lib/articlesActions"; // One article's buttons on the Articles tab: Publish for a draft; Up, Down and // Unpublish for a published one; and its audience — Make public / Make // private. Each is one write through the article registry // (lib/articlesActions.ts); the action revalidates the tab. export function ArticleRowActions({ articleId, position, publishedCount, publishable, audience, }: { articleId: string; // Its place in the published list, or null for a draft. position: number | null; publishedCount: number; // Why it may not be published, or null when it may. publishable: string | null; audience: "public" | "private"; }) { const [pending, start] = useTransition(); const [error, setError] = useState(null); const run = (fn: () => Promise) => { setError(null); start(async () => { const res = await fn(); if (!res.ok) setError(res.error); }); }; const btn = "rounded border border-border px-2 py-1 text-xs hover:bg-muted disabled:opacity-50"; const other = audience === "public" ? "private" : "public"; return ( {position === null ? ( ) : ( <> )} {error && ( {error} )} ); }