// @flow
import React from 'react';
import AbstractPollResults from '../AbstractPollResults';
import type { AbstractProps } from '../AbstractPollResults';
/**
* Component that renders the poll results.
*
* @param {Props} props - The passed props.
* @returns {React.Node}
*/
const PollResults = (props: AbstractProps) => {
const {
answers,
changeVote,
creatorName,
haveVoted,
showDetails,
question,
t,
toggleIsDetailed
} = props;
return (
{ question }
{ t('polls.by', { name: creatorName }) }
{answers.map(({ name, percentage, voters, voterCount }, index) =>
(-
{name}
({voterCount}) {percentage}%
{ showDetails && voters && voterCount > 0
&&
{voters.map(voter =>
- {voter.name}
)}
}
)
)}
);
};
/*
* We apply AbstractPollResults to fill in the AbstractProps common
* to both the web and native implementations.
*/
// eslint-disable-next-line new-cap
export default AbstractPollResults(PollResults);