info.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import React from "react"
  2. import escapeHtml from "misago/utils/escape-html"
  3. const DATE_ABBR = '<abbr title="%(absolute)s">%(relative)s</abbr>'
  4. const USER_SPAN = '<span class="item-title">%(user)s</span>'
  5. const USER_URL = '<a href="%(url)s" class="item-title">%(user)s</a>'
  6. export default function(props) {
  7. return (
  8. <ul className="list-unstyled list-inline poll-details">
  9. <PollVotes votes={props.poll.votes} />
  10. <PollLength poll={props.poll} />
  11. <PollIsPublic poll={props.poll} />
  12. <PollCreation poll={props.poll} />
  13. </ul>
  14. )
  15. }
  16. export function PollCreation(props) {
  17. const message = interpolate(
  18. escapeHtml(gettext("Posted by %(poster)s %(posted_on)s.")),
  19. {
  20. poster: getPoster(props.poll),
  21. posted_on: getPostedOn(props.poll)
  22. },
  23. true
  24. )
  25. return (
  26. <li
  27. className="poll-info-creation"
  28. dangerouslySetInnerHTML={{ __html: message }}
  29. />
  30. )
  31. }
  32. export function getPoster(poll) {
  33. if (poll.url.poster) {
  34. return interpolate(
  35. USER_URL,
  36. {
  37. url: escapeHtml(poll.url.poster),
  38. user: escapeHtml(poll.poster_name)
  39. },
  40. true
  41. )
  42. }
  43. return interpolate(
  44. USER_SPAN,
  45. {
  46. user: escapeHtml(poll.poster_name)
  47. },
  48. true
  49. )
  50. }
  51. export function getPostedOn(poll) {
  52. return interpolate(
  53. DATE_ABBR,
  54. {
  55. absolute: escapeHtml(poll.posted_on.format("LLL")),
  56. relative: escapeHtml(poll.posted_on.fromNow())
  57. },
  58. true
  59. )
  60. }
  61. export function PollLength(props) {
  62. if (!props.poll.length) {
  63. return null
  64. }
  65. const message = interpolate(
  66. escapeHtml(gettext("Voting ends %(ends_on)s.")),
  67. {
  68. ends_on: getEndsOn(props.poll)
  69. },
  70. true
  71. )
  72. return (
  73. <li
  74. className="poll-info-ends-on"
  75. dangerouslySetInnerHTML={{ __html: message }}
  76. />
  77. )
  78. }
  79. export function getEndsOn(poll) {
  80. return interpolate(
  81. DATE_ABBR,
  82. {
  83. absolute: escapeHtml(poll.endsOn.format("LLL")),
  84. relative: escapeHtml(poll.endsOn.fromNow())
  85. },
  86. true
  87. )
  88. }
  89. export function PollVotes(props) {
  90. const message = ngettext("%(votes)s vote.", "%(votes)s votes.", props.votes)
  91. const label = interpolate(
  92. message,
  93. {
  94. votes: props.votes
  95. },
  96. true
  97. )
  98. return <li className="poll-info-votes">{label}</li>
  99. }
  100. export function PollIsPublic(props) {
  101. if (!props.poll.is_public) {
  102. return null
  103. }
  104. return <li className="poll-info-public">{gettext("Votes are public.")}</li>
  105. }