paginator.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. import React from "react"
  2. import { Link } from "react-router"
  3. export default function(props) {
  4. return (
  5. <nav className="misago-pagination pull-left">
  6. <Pager {...props} />
  7. <More more={props.posts.more} />
  8. </nav>
  9. )
  10. }
  11. export function Pager(props) {
  12. return (
  13. <div className="row row-paginator">
  14. <div className="col-xs-3">
  15. <FirstPage {...props} />
  16. </div>
  17. <div className="col-xs-3">
  18. <PreviousPage {...props} />
  19. </div>
  20. <div className="col-xs-3">
  21. <NextPage {...props} />
  22. </div>
  23. <div className="col-xs-3">
  24. <LastPage {...props} />
  25. </div>
  26. </div>
  27. )
  28. }
  29. export function FirstPage(props) {
  30. if (props.posts.isLoaded && props.posts.first) {
  31. return (
  32. <Link
  33. className="btn btn-default btn-block btn-outline btn-icon"
  34. to={props.thread.url.index}
  35. title={gettext("Go to first page")}
  36. >
  37. <span className="material-icon">first_page</span>
  38. </Link>
  39. )
  40. } else {
  41. return (
  42. <span
  43. className="btn btn-default btn-block btn-outline btn-icon disabled"
  44. title={gettext("Go to first page")}
  45. >
  46. <span className="material-icon">first_page</span>
  47. </span>
  48. )
  49. }
  50. }
  51. export function PreviousPage(props) {
  52. if (props.posts.isLoaded && props.posts.page > 1) {
  53. let previousUrl = ""
  54. if (props.posts.previous) {
  55. previousUrl = props.posts.previous + "/"
  56. }
  57. return (
  58. <Link
  59. className="btn btn-default btn-block btn-outline btn-icon"
  60. to={props.thread.url.index + previousUrl}
  61. title={gettext("Go to previous page")}
  62. >
  63. <span className="material-icon">chevron_left</span>
  64. </Link>
  65. )
  66. } else {
  67. return (
  68. <span
  69. className="btn btn-default btn-block btn-outline btn-icon disabled"
  70. title={gettext("Go to previous page")}
  71. >
  72. <span className="material-icon">chevron_left</span>
  73. </span>
  74. )
  75. }
  76. }
  77. export function NextPage(props) {
  78. if (props.posts.isLoaded && props.posts.more) {
  79. let nextUrl = ""
  80. if (props.posts.next) {
  81. nextUrl = props.posts.next + "/"
  82. }
  83. return (
  84. <Link
  85. className="btn btn-default btn-block btn-outline btn-icon"
  86. to={props.thread.url.index + nextUrl}
  87. title={gettext("Go to next page")}
  88. >
  89. <span className="material-icon">chevron_right</span>
  90. </Link>
  91. )
  92. } else {
  93. return (
  94. <span
  95. className="btn btn-default btn-block btn-outline btn-icon disabled"
  96. title={gettext("Go to next page")}
  97. >
  98. <span className="material-icon">chevron_right</span>
  99. </span>
  100. )
  101. }
  102. }
  103. export function LastPage(props) {
  104. if (props.posts.isLoaded && props.posts.last) {
  105. return (
  106. <Link
  107. className="btn btn-default btn-block btn-outline btn-icon"
  108. to={props.thread.url.index + props.posts.last + "/"}
  109. title={gettext("Go to last page")}
  110. >
  111. <span className="material-icon">last_page</span>
  112. </Link>
  113. )
  114. } else {
  115. return (
  116. <span
  117. className="btn btn-default btn-block btn-outline btn-icon disabled"
  118. title={gettext("Go to last page")}
  119. >
  120. <span className="material-icon">last_page</span>
  121. </span>
  122. )
  123. }
  124. }
  125. export function More(props) {
  126. let message = null
  127. if (props.more) {
  128. message = ngettext(
  129. "There is %(more)s more post in this thread.",
  130. "There are %(more)s more posts in this thread.",
  131. props.more
  132. )
  133. message = interpolate(message, { more: props.more }, true)
  134. } else {
  135. message = gettext("There are no more posts in this thread.")
  136. }
  137. return <p>{message}</p>
  138. }