"use client"; import { useRouter } from "next/navigation"; import React from "react"; import { useTransition } from "react"; import { castTechVote } from "@/app/(frontend)/intelligence/tech-tree/actions"; /** * Cast/change the caller's vote on a ballot option. Tactical squared button * (the panel it lives in is the dossier surface; the button stays compact per * the style guide's "never dossier on buttons" rule but keeps the mono look). */ export function VoteButton({ ballotId, technologyId, isMyVote, disabled, }: { ballotId: number; technologyId: number; isMyVote: boolean; disabled?: boolean; }) { const router = useRouter(); const [pending, startTransition] = useTransition(); const [error, setError] = React.useState(null); const onClick = () => { setError(null); startTransition(async () => { const result = await castTechVote({ ballotId, technologyId }); if (!result.success) { setError(result.error ?? "Vote failed."); return; } router.refresh(); }); }; return ( {error ? ( {error} ) : null} ); }