user-card.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. getUserTitle() {
  41. if (this.props.user.title) {
  42. /* jshint ignore:start */
  43. return <span className="user-title">{this.props.user.title}</span>;
  44. /* jshint ignore:end */
  45. } else {
  46. return null;
  47. }
  48. }
  49. getUserJoinedOn() {
  50. /* jshint ignore:start */
  51. let title = interpolate(gettext("Joined on %(joined_on)s"), {
  52. 'joined_on': this.props.user.joined_on.format('LL, LT')
  53. }, true);
  54. let age = interpolate(gettext("Joined %(joined_on)s"), {
  55. 'joined_on': this.props.user.joined_on.fromNow()
  56. }, true);
  57. return <span className="user-joined-on" title={title}>
  58. {age}
  59. </span>;
  60. /* jshint ignore:end */
  61. }
  62. render() {
  63. /* jshint ignore:start */
  64. return <div className={this.getClassName()}>
  65. <div className="user-card-bg-image">
  66. <Avatar user={this.props.user} size="400" className="bg-image" />
  67. <div className="user-card-bg">
  68. <div className="user-details">
  69. <div className="user-avatar">
  70. <a href={this.props.user.absolute_url}>
  71. <Avatar user={this.props.user} size="400" />
  72. </a>
  73. </div>
  74. <h4 className="user-name">
  75. <a href={this.props.user.absolute_url} className="item-title">
  76. {this.props.user.username}
  77. </a>
  78. </h4>
  79. <p className="user-subscript">
  80. {this.getUserStatus()}
  81. {this.getUserTitle()}
  82. {this.getUserJoinedOn()}
  83. </p>
  84. </div>
  85. <div className="user-card-stats">
  86. <ul className="list-unstyled">
  87. <li className="user-posts-count">
  88. <strong>{this.props.user.posts}</strong>
  89. <small>{gettext("posts")}</small>
  90. </li>
  91. <li className="user-threads-count">
  92. <strong>{this.props.user.threads}</strong>
  93. <small>{gettext("threads")}</small>
  94. </li>
  95. <li className="user-followers-count">
  96. <strong>{this.props.user.followers}</strong>
  97. <small>{gettext("followers")}</small>
  98. </li>
  99. </ul>
  100. </div>
  101. </div>
  102. </div>
  103. </div>;
  104. /* jshint ignore:end */
  105. }
  106. }