ready.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import React from "react"
  2. import Avatar from "misago/components/avatar"
  3. import { BottomDetails, TopDetails } from "./details"
  4. import LastAction from "./last-action"
  5. import { Options } from "./options"
  6. import UserUrl from "./user-url"
  7. export default function(props) {
  8. const {
  9. activeCategory,
  10. categories,
  11. list,
  12. thread,
  13. isBusy,
  14. isSelected,
  15. showOptions
  16. } = props
  17. let category = null
  18. if (activeCategory.id !== thread.category) {
  19. category = categories[thread.category]
  20. }
  21. const flavor = category || activeCategory
  22. let className = "thread-main col-xs-12"
  23. if (showOptions) {
  24. if (thread.moderation.length) {
  25. className += " col-sm-9 col-md-7"
  26. } else {
  27. className += " col-sm-10 col-md-7"
  28. }
  29. } else {
  30. className += " col-sm-12 col-md-9"
  31. }
  32. return (
  33. <li className={getClassName(thread.is_read, isBusy, isSelected, flavor)}>
  34. <TopDetails category={category} thread={thread} />
  35. <div className="row thread-row">
  36. <div className={className}>
  37. <div className="media">
  38. <div className="media-left hidden-xs">
  39. <UserUrl
  40. className="thread-starter-avatar"
  41. title={thread.starter_name}
  42. url={thread.url.starter}
  43. >
  44. <Avatar size={40} user={thread.starter} />
  45. </UserUrl>
  46. </div>
  47. <div className="media-body">
  48. <a href={thread.url.index} className="item-title thread-title">
  49. {thread.title}
  50. </a>
  51. <BottomDetails
  52. category={category}
  53. disabled={isBusy}
  54. isSelected={isSelected}
  55. showOptions={showOptions}
  56. thread={thread}
  57. />
  58. </div>
  59. </div>
  60. </div>
  61. <div className="col-md-3 hidden-xs hidden-sm thread-last-action">
  62. <LastAction thread={thread} />
  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, flavor) {
  75. let styles = ["list-group-item"]
  76. if (flavor && flavor.css_class) {
  77. styles.push("list-group-category-has-flavor")
  78. styles.push("list-group-item-category-" + flavor.css_class)
  79. }
  80. if (isRead) {
  81. styles.push("thread-read")
  82. } else {
  83. styles.push("thread-new")
  84. }
  85. if (isBusy) {
  86. styles.push("thread-busy")
  87. } else if (isSelected) {
  88. styles.push("thread-selected")
  89. }
  90. return styles.join(" ")
  91. }