diff --git a/app/soapbox/components/poll.tsx b/app/soapbox/components/poll.tsx index b11925fff..577426a0c 100644 --- a/app/soapbox/components/poll.tsx +++ b/app/soapbox/components/poll.tsx @@ -1,18 +1,19 @@ import classNames from 'classnames'; -import React from 'react'; -import ImmutablePureComponent from 'react-immutable-pure-component'; -import { defineMessages, injectIntl, FormattedMessage, IntlShape } from 'react-intl'; +import React, { useState } from 'react'; +import { defineMessages, useIntl, FormattedMessage } from 'react-intl'; import { spring } from 'react-motion'; +import { useDispatch } from 'react-redux'; import { openModal } from 'soapbox/actions/modals'; import { vote, fetchPoll } from 'soapbox/actions/polls'; import Icon from 'soapbox/components/icon'; -import { Text } from 'soapbox/components/ui'; +import { Text, Button, Stack, HStack } from 'soapbox/components/ui'; import Motion from 'soapbox/features/ui/util/optional_motion'; +import { useAppSelector } from 'soapbox/hooks'; import RelativeTimestamp from './relative_timestamp'; -import type { Poll as PollEntity, PollOption } from 'soapbox/types/entities'; +import type { Poll as PollEntity, PollOption as PollOptionEntity } from 'soapbox/types/entities'; const messages = defineMessages({ closed: { id: 'poll.closed', defaultMessage: 'Closed' }, @@ -20,172 +21,239 @@ const messages = defineMessages({ votes: { id: 'poll.votes', defaultMessage: '{votes, plural, one {# vote} other {# votes}}' }, }); +const PollPercentageBar: React.FC<{percent: number, leading: boolean}> = ({ percent, leading }): JSX.Element => { + return ( + + {({ width }) =>( + + )} + + ); +}; + +interface IPollOptionText extends IPollOption { + percent: number, +} + +const PollOptionText: React.FC = ({ poll, option, index, active, percent, showResults, onToggle }) => { + const intl = useIntl(); + const voted = poll.own_votes?.includes(index); + const message = intl.formatMessage(messages.votes, { votes: option.votes_count }); + + const handleOptionChange: React.EventHandler = () => { + onToggle(index); + }; + + const handleOptionKeyPress: React.EventHandler = e => { + if (e.key === 'Enter' || e.key === ' ') { + onToggle(index); + e.stopPropagation(); + e.preventDefault(); + } + }; + + return ( +