user-card.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. import React from 'react';
  2. import Avatar from 'misago/components/avatar'; // jshint ignore:line
  3. import Status, { StatusIcon, StatusLabel } from 'misago/components/user-status'; // jshint ignore:line
  4. export default class extends React.Component {
  5. getClassName() {
  6. if (this.props.user.rank.css_class) {
  7. return 'user-card user-card-' + this.props.user.rank.css_class + ' ui-ready';
  8. } else {
  9. return 'user-card ui-ready';
  10. }
  11. }
  12. getUserStatus() {
  13. if (this.props.showStatus) {
  14. if (this.props.user.status) {
  15. /* jshint ignore:start */
  16. return <Status user={this.props.user} status={this.props.user.status}>
  17. <StatusIcon user={this.props.user}
  18. status={this.props.user.status} />
  19. <StatusLabel user={this.props.user}
  20. status={this.props.user.status}
  21. className="status-label" />
  22. </Status>;
  23. /* jshint ignore:end */
  24. } else {
  25. /* jshint ignore:start */
  26. return <span className="user-status">
  27. <span className="status-icon ui-preview">
  28. &nbsp;
  29. </span>
  30. <span className="status-label ui-preview">
  31. &nbsp;
  32. </span>
  33. </span>;
  34. /* jshint ignore:end */
  35. }
  36. } else {
  37. return null;
  38. }
  39. }
  40. getRankName() {
  41. if (this.props.showRank) {
  42. if (this.props.user.rank.is_tab) {
  43. /* jshint ignore:start */
  44. return <a href={this.props.user.rank.absolute_url}
  45. className="item-title rank-name">
  46. {this.props.user.rank.name}
  47. </a>;
  48. /* jshint ignore:end */
  49. } else {
  50. /* jshint ignore:start */
  51. return <span className="item-title rank-name">
  52. {this.props.user.rank.name}
  53. </span>;
  54. /* jshint ignore:end */
  55. }
  56. } else {
  57. return null;
  58. }
  59. }
  60. getUserTitle() {
  61. if (this.props.user.title) {
  62. /* jshint ignore:start */
  63. return <span className="user-title">{this.props.user.title}</span>;
  64. /* jshint ignore:end */
  65. } else {
  66. return null;
  67. }
  68. }
  69. getUserJoinedOn() {
  70. /* jshint ignore:start */
  71. let title = interpolate(gettext("Joined on %(joined_on)s"), {
  72. 'joined_on': this.props.user.joined_on.format('LL, LT')
  73. }, true);
  74. let age = interpolate(gettext("Joined %(joined_on)s"), {
  75. 'joined_on': this.props.user.joined_on.fromNow()
  76. }, true);
  77. return <span className="user-joined-on" title={title}>
  78. {age}
  79. </span>;
  80. /* jshint ignore:end */
  81. }
  82. getPostsCount() {
  83. let message = ngettext(
  84. "%(posts)s post",
  85. "%(posts)s posts",
  86. this.props.user.posts);
  87. return interpolate(message, {
  88. 'posts': this.props.user.posts
  89. }, true);
  90. }
  91. getThreadsCount() {
  92. let message = ngettext(
  93. "%(threads)s thread",
  94. "%(threads)s threads",
  95. this.props.user.threads);
  96. return interpolate(message, {
  97. 'threads': this.props.user.threads
  98. }, true);
  99. }
  100. getFollowersCount() {
  101. let message = ngettext(
  102. "%(followers)s follower",
  103. "%(followers)s followers",
  104. this.props.user.followers);
  105. return interpolate(message, {
  106. 'followers': this.props.user.followers
  107. }, true);
  108. }
  109. render() {
  110. /* jshint ignore:start */
  111. return <div className={this.getClassName()}>
  112. <div className="user-card-bg-image">
  113. <Avatar user={this.props.user} size="400" className="bg-image" />
  114. <div className="user-card-bg">
  115. <div className="user-details">
  116. <div className="user-avatar">
  117. <a href={this.props.user.absolute_url}>
  118. <Avatar user={this.props.user} size="400" />
  119. </a>
  120. </div>
  121. <h4 className="user-name">
  122. <a href={this.props.user.absolute_url} className="item-title">
  123. {this.props.user.username}
  124. </a>
  125. </h4>
  126. <p className="user-subscript">
  127. {this.getUserStatus()}
  128. {this.getRankName()}
  129. {this.getUserTitle()}
  130. {this.getUserJoinedOn()}
  131. </p>
  132. </div>
  133. <div className="user-card-stats">
  134. <ul className="list-unstyled">
  135. <li className="user-posts-count">
  136. {this.getPostsCount()}
  137. </li>
  138. <li className="user-threads-count">
  139. {this.getThreadsCount()}
  140. </li>
  141. <li className="user-followers-count">
  142. {this.getFollowersCount()}
  143. </li>
  144. </ul>
  145. </div>
  146. </div>
  147. </div>
  148. </div>;
  149. /* jshint ignore:end */
  150. }
  151. }