import React from 'react'; import { defineMessages, FormattedMessage, useIntl } from 'react-intl'; import { fetchPoll, vote } from 'soapbox/actions/polls'; import { useAppDispatch } from 'soapbox/hooks'; import RelativeTimestamp from '../relative-timestamp'; import { Button, HStack, Stack, Text, Tooltip } from '../ui'; import type { Selected } from './poll'; import type { Poll as PollEntity } from 'soapbox/types/entities'; const messages = defineMessages({ closed: { id: 'poll.closed', defaultMessage: 'Closed' }, nonAnonymous: { id: 'poll.non_anonymous.label', defaultMessage: 'Other instances may display the options you voted for' }, }); interface IPollFooter { poll: PollEntity showResults: boolean selected: Selected } const PollFooter: React.FC = ({ poll, showResults, selected }): JSX.Element => { const dispatch = useAppDispatch(); const intl = useIntl(); const handleVote = () => dispatch(vote(poll.id, Object.keys(selected))); const handleRefresh: React.EventHandler = (e) => { dispatch(fetchPoll(poll.id)); e.stopPropagation(); e.preventDefault(); }; const timeRemaining = poll.expired ? intl.formatMessage(messages.closed) : ; let votesCount = null; if (poll.voters_count !== null && poll.voters_count !== undefined) { votesCount = ; } else { votesCount = ; } return ( {(!showResults && poll.multiple) && ( )} {poll.pleroma?.non_anonymous && ( <> · )} {showResults && ( <> · )} {votesCount} {poll.expires_at && ( <> · {timeRemaining} )} ); }; export default PollFooter;