{options.map((optionText, index) => {
const optionKey = ["a", "b", "c", "d"][index] as
| "a"
| "b"
| "c"
| "d";
const { topVoterDids } = results[optionKey];
const optionState = results[optionKey];
const hasVotedForOption = optionState.hasVoted;
const votePercentage =
totalVotes > 0 ? (optionState.count / totalVotes) * 100 : 0;
const votersData = (() => {
if (optionKey === "a") return votersA?.linking_records || [];
if (optionKey === "b") return votersB?.linking_records || [];
if (optionKey === "c") return votersC?.linking_records || [];
if (optionKey === "d") return votersD?.linking_records || [];
return [];
})();
const topVoters = votersData
.filter((v: any) => !!v.did)
.slice(0, 5);
return (
{
e.stopPropagation();
if (!isExpired) {
handleVote(optionKey);
}
}}
>
{optionText}
{hasVotedForOption && (
{poll.multiple ? "✓" : "✓ (click to remove)"}
)}
{topVoterDids.length > 0 && (
{topVoterDids.map((did, idx) => (
))}
)}
{votePercentage.toFixed(0)}%
);
})}