import clsx from 'clsx' import { useEffect, useState } from 'react' import { useTranslation } from 'react-i18next' import { ProposalVoterProps } from '@dao-dao/types' import { Button } from '../buttons' import { StatusCard } from '../StatusCard' import { ProposalVoteButton } from './ProposalVoteButton' export const ProposalVoter = ({ loading, currentVote, onCastVote, options, proposalOpen, className, }: ProposalVoterProps) => { const { t } = useTranslation() const [selectedVote, setSelectedVote] = useState( currentVote ) // If currentVote changes, reset selected vote to it. useEffect(() => { setSelectedVote(currentVote) }, [currentVote]) const currentVoteOption = currentVote ? options.find((option) => option.value === currentVote) : undefined // If the wallet's current vote is the selected vote. This means revoting is // allowed, and the current vote selected is the same vote as before. const currentVoteSelected = !!currentVoteOption && selectedVote === currentVoteOption.value return (
{/* If proposal no longer open but voting is allowed, explain why. */} {!proposalOpen && ( )}
{options.map((option, index) => ( setSelectedVote(option.value)} option={option} pressed={option.value === selectedVote} /> ))}
) } export const ProposalVoterLoading = ( props: Omit, 'loading' | 'currentVote' | 'onCastVote'> ) => {}} {...props} />