From da1caf93dd0e13639c378311106a4d71a4645fce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marcin=20miko=C5=82ajczak?= Date: Fri, 22 Jul 2022 23:48:27 +0200 Subject: [PATCH] For multi-response polls, show the number of people that voted instead of the sum of all votes submitted MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: marcin mikołajczak --- app/soapbox/components/polls/poll-footer.tsx | 15 ++++++++++----- app/soapbox/components/polls/poll-option.tsx | 3 ++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/soapbox/components/polls/poll-footer.tsx b/app/soapbox/components/polls/poll-footer.tsx index bfa105ebd..c7997cfd7 100644 --- a/app/soapbox/components/polls/poll-footer.tsx +++ b/app/soapbox/components/polls/poll-footer.tsx @@ -36,6 +36,15 @@ const PollFooter: React.FC = ({ poll, showResults, selected }): JSX intl.formatMessage(messages.closed) : ; + let votesCount = null; + + if (poll.voters_count !== null && poll.voters_count !== undefined) { + votesCount = ; + } else { + votesCount = ; + } + + return ( {(!showResults && poll?.multiple) && ( @@ -58,11 +67,7 @@ const PollFooter: React.FC = ({ poll, showResults, selected }): JSX )} - + {votesCount} {poll.expires_at && ( diff --git a/app/soapbox/components/polls/poll-option.tsx b/app/soapbox/components/polls/poll-option.tsx index b242f649b..024f01b7b 100644 --- a/app/soapbox/components/polls/poll-option.tsx +++ b/app/soapbox/components/polls/poll-option.tsx @@ -110,7 +110,8 @@ const PollOption: React.FC = (props): JSX.Element | null => { if (!poll) return null; - const percent = poll.votes_count === 0 ? 0 : (option.votes_count / poll.votes_count) * 100; + const pollVotesCount = poll.voters_count || poll.votes_count; + const percent = pollVotesCount === 0 ? 0 : (option.votes_count / pollVotesCount) * 100; const leading = poll.options.filterNot(other => other.title === option.title).every(other => option.votes_count >= other.votes_count); const voted = poll.own_votes?.includes(index); const message = intl.formatMessage(messages.votes, { votes: option.votes_count });