1
0
Fork 0
polaris-task-force/src/components/frontend/techTree/VoteButton.tsx
Z8MB1E afa79b4be4 feat(tech): member-facing tech research system and tech tree
Add a research pipeline over the existing technology tree: Research
Facility blueprint fields copied to structure instances, tech-researches/
tech-ballots/tech-ballot-votes collections, Game Rules research config,
pure rules lib (capacity, duration math, eligibility, intel-weighted
tally with tie cascade), a timestamp-derived tech-tick bin that opens,
resolves, advances and completes research with notifications, vote
casting server actions, and a read-only member-facing tech tree page at
/intelligence/tech-tree with veil blackout and dossier-style panels.

Includes migration 20261019_184409_add_tech_research_system, permission
groups, event and notification types, sidebar entry, and integration
plus e2e coverage.
2026-10-19 17:28:26 -04:00

61 lines
1.8 KiB
TypeScript

"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<string | null>(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 (
<span className="inline-flex flex-col items-end gap-0.5">
<button
type="button"
onClick={onClick}
disabled={pending || disabled}
data-testid={`tech-vote-${technologyId}`}
className={`rounded-none border px-2 py-1 font-mono text-[9px] tracking-widest uppercase transition-colors ${
isMyVote
? "border-[#22d3ee]/60 bg-[#22d3ee]/15 text-[#a5f3fc]"
: "border-white/20 bg-black/50 text-white/75 hover:border-white/45 hover:bg-white/10 hover:text-white"
} disabled:cursor-not-allowed disabled:opacity-50`}
>
{pending ? "Saving…" : isMyVote ? "Voted ✓" : "Cast Vote"}
</button>
{error ? (
<span className="font-mono text-[8px] text-red-400">{error}</span>
) : null}
</span>
);
}