ready.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /* jshint ignore:start */
  2. import React from 'react';
  3. import { BottomDetails, TopDetails } from './details';
  4. import { Options } from './options';
  5. export default function(props) {
  6. const {
  7. activeCategory,
  8. categories,
  9. list,
  10. thread,
  11. isBusy,
  12. isSelected,
  13. showOptions,
  14. } = props;
  15. let category = null;
  16. if (activeCategory.id !== thread.category) {
  17. category = categories[thread.category];
  18. }
  19. let className = 'thread-main col-xs-12';
  20. if (showOptions) {
  21. if (thread.moderation.length) {
  22. className += ' col-sm-9 col-md-7';
  23. } else {
  24. className += ' col-sm-10 col-md-7';
  25. }
  26. } else {
  27. className += ' col-sm-12 col-md-9';
  28. }
  29. return (
  30. <li className={getClassName(thread.is_read, isBusy, isSelected)}>
  31. <div className="row thread-row">
  32. <div className={className}>
  33. <TopDetails
  34. category={category}
  35. thread={thread}
  36. />
  37. <a href={thread.url.index} className="item-title thread-title">
  38. {thread.title}
  39. </a>
  40. <BottomDetails
  41. category={category}
  42. disabled={isBusy}
  43. isSelected={isSelected}
  44. showOptions={showOptions}
  45. thread={thread}
  46. />
  47. </div>
  48. <div className="col-md-3 hidden-xs hidden-sm thread-last-action">
  49. <div className="row">
  50. <div className="col-xs-5">
  51. <Timestamp
  52. datetime={thread.last_post_on}
  53. url={thread.url.last_post}
  54. />
  55. </div>
  56. <div className="col-xs-7">
  57. <LastPoster
  58. posterName={thread.last_poster_name}
  59. url={thread.url.last_poster}
  60. />
  61. </div>
  62. </div>
  63. </div>
  64. <Options
  65. disabled={isBusy}
  66. display={showOptions}
  67. isSelected={isSelected}
  68. thread={thread}
  69. />
  70. </div>
  71. </li>
  72. );
  73. }
  74. export function getClassName(isRead, isBusy, isSelected) {
  75. let styles = ['list-group-item'];
  76. if (isRead) {
  77. styles.push('thread-read');
  78. } else {
  79. styles.push('thread-new');
  80. }
  81. if (isBusy) {
  82. styles.push('thread-busy');
  83. } else if (isSelected) {
  84. styles.push('thread-selected');
  85. }
  86. return styles.join(' ');
  87. }
  88. export function Timestamp({ datetime, url }) {
  89. return (
  90. <a href={url} title={datetime.format('LLL')}>
  91. {datetime.fromNow(true)}
  92. </a>
  93. );
  94. }
  95. export function LastPoster(props) {
  96. const { posterName, url } = props;
  97. if (url) {
  98. return (
  99. <a
  100. className="item-title thread-last-poster"
  101. href={url}
  102. >
  103. {posterName}
  104. </a>
  105. );
  106. }
  107. return (
  108. <span className="item-title thread-last-poster">
  109. {posterName}
  110. </span>
  111. );
  112. }