From b124705bfd9c7422eff6cbca73cd734f0ab9781a Mon Sep 17 00:00:00 2001 From: Justin Date: Wed, 15 Jun 2022 15:59:17 -0400 Subject: [PATCH] Refactor polls --- app/soapbox/components/poll.tsx | 290 ------------------- app/soapbox/components/polls/poll-footer.tsx | 79 +++++ app/soapbox/components/polls/poll-option.tsx | 157 ++++++++++ app/soapbox/components/polls/poll.tsx | 89 ++++++ app/soapbox/components/status_content.tsx | 3 +- 5 files changed, 327 insertions(+), 291 deletions(-) delete mode 100644 app/soapbox/components/poll.tsx create mode 100644 app/soapbox/components/polls/poll-footer.tsx create mode 100644 app/soapbox/components/polls/poll-option.tsx create mode 100644 app/soapbox/components/polls/poll.tsx diff --git a/app/soapbox/components/poll.tsx b/app/soapbox/components/poll.tsx deleted file mode 100644 index e8742ab5f..000000000 --- a/app/soapbox/components/poll.tsx +++ /dev/null @@ -1,290 +0,0 @@ -import classNames from 'classnames'; -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 { Text, Button, Icon, 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 as PollOptionEntity } from 'soapbox/types/entities'; - -const messages = defineMessages({ - closed: { id: 'poll.closed', defaultMessage: 'Closed' }, - voted: { id: 'poll.voted', defaultMessage: 'You voted for this answer' }, - 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 ( -