You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PollResults.js 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // @flow
  2. import React from 'react';
  3. import AbstractPollResults from '../AbstractPollResults';
  4. import type { AbstractProps } from '../AbstractPollResults';
  5. /**
  6. * Component that renders the poll results.
  7. *
  8. * @param {Props} props - The passed props.
  9. * @returns {React.Node}
  10. */
  11. const PollResults = (props: AbstractProps) => {
  12. const {
  13. answers,
  14. changeVote,
  15. creatorName,
  16. haveVoted,
  17. showDetails,
  18. question,
  19. t,
  20. toggleIsDetailed
  21. } = props;
  22. return (
  23. <div className = 'poll-results'>
  24. <div className = 'poll-header'>
  25. <div className = 'poll-question'>
  26. <strong>{ question }</strong>
  27. </div>
  28. <div className = 'poll-creator'>
  29. { t('polls.by', { name: creatorName }) }
  30. </div>
  31. </div>
  32. <ol className = 'poll-result-list'>
  33. {answers.map(({ name, percentage, voters, voterCount }, index) =>
  34. (<li key = { index }>
  35. <div className = 'poll-answer-header'>
  36. <span className = 'poll-answer-vote-name' >{name}</span>
  37. </div>
  38. <div className = 'poll-answer-short-results'>
  39. <span className = 'poll-bar-container'>
  40. <div
  41. className = 'poll-bar'
  42. style = {{ width: `${percentage}%` }} />
  43. </span>
  44. <div className = 'poll-answer-vote-count-container'>
  45. <span className = 'poll-answer-vote-count'>({voterCount}) {percentage}%</span>
  46. </div>
  47. </div>
  48. { showDetails && voters && voterCount > 0
  49. && <ul className = 'poll-answer-voters'>
  50. {voters.map(voter =>
  51. <li key = { voter.id }>{voter.name}</li>
  52. )}
  53. </ul>}
  54. </li>)
  55. )}
  56. </ol>
  57. <div className = { 'poll-result-links' }>
  58. <a
  59. className = { 'poll-detail-link' }
  60. onClick = { toggleIsDetailed }>
  61. {showDetails ? t('polls.results.hideDetailedResults') : t('polls.results.showDetailedResults')}
  62. </a>
  63. <a
  64. className = { 'poll-change-vote-link' }
  65. onClick = { changeVote }>
  66. {haveVoted ? t('polls.results.changeVote') : t('polls.results.vote')}
  67. </a>
  68. </div>
  69. </div>
  70. );
  71. };
  72. /*
  73. * We apply AbstractPollResults to fill in the AbstractProps common
  74. * to both the web and native implementations.
  75. */
  76. // eslint-disable-next-line new-cap
  77. export default AbstractPollResults(PollResults);