user-status.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import React from 'react';
  2. export default class extends React.Component {
  3. getClass() {
  4. let status = '';
  5. if (this.props.status.is_banned) {
  6. status = 'banned';
  7. } else if (this.props.status.is_hidden) {
  8. status = 'offline';
  9. } else if (this.props.status.is_online_hidden) {
  10. status = 'online';
  11. } else if (this.props.status.is_offline_hidden) {
  12. status = 'offline';
  13. } else if (this.props.status.is_online) {
  14. status = 'online';
  15. } else if (this.props.status.is_offline) {
  16. status = 'offline';
  17. }
  18. return 'user-status user-' + status;
  19. }
  20. render() {
  21. /* jshint ignore:start */
  22. return <span className={this.getClass()}>
  23. {this.props.children}
  24. </span>;
  25. /* jshint ignore:end */
  26. }
  27. }
  28. export class StatusIcon extends React.Component {
  29. getIcon() {
  30. if (this.props.status.is_banned) {
  31. return 'remove_circle_outline';
  32. } else if (this.props.status.is_hidden) {
  33. return 'help_outline';
  34. } else if (this.props.status.is_online_hidden) {
  35. return 'label';
  36. } else if (this.props.status.is_offline_hidden) {
  37. return 'label_outline';
  38. } else if (this.props.status.is_online) {
  39. return 'lens';
  40. } else if (this.props.status.is_offline) {
  41. return 'panorama_fish_eye';
  42. }
  43. }
  44. render() {
  45. /* jshint ignore:start */
  46. return <span className="material-icon status-icon">
  47. {this.getIcon()}
  48. </span>;
  49. /* jshint ignore:end */
  50. }
  51. }
  52. export class StatusLabel extends React.Component {
  53. getHelp() {
  54. if (this.props.status.is_banned) {
  55. if (this.props.status.banned_until) {
  56. return interpolate(gettext("%(username)s is banned until %(ban_expires)s"), {
  57. username: this.props.user.username,
  58. ban_expires: this.props.status.banned_until.format('LL, LT')
  59. }, true);
  60. } else {
  61. return interpolate(gettext("%(username)s is banned"), {
  62. username: this.props.user.username
  63. }, true);
  64. }
  65. } else if (this.props.status.is_hidden) {
  66. return interpolate(gettext("%(username)s is hiding presence"), {
  67. username: this.props.user.username
  68. }, true);
  69. } else if (this.props.status.is_online_hidden) {
  70. return interpolate(gettext("%(username)s is online (hidden)"), {
  71. username: this.props.user.username
  72. }, true);
  73. } else if (this.props.status.is_offline_hidden) {
  74. return interpolate(gettext("%(username)s was last seen %(last_click)s (hidden)"), {
  75. username: this.props.user.username,
  76. last_click: this.props.status.last_click.fromNow()
  77. }, true);
  78. } else if (this.props.status.is_online) {
  79. return interpolate(gettext("%(username)s is online"), {
  80. username: this.props.user.username
  81. }, true);
  82. } else if (this.props.status.is_offline) {
  83. return interpolate(gettext("%(username)s was last seen %(last_click)s"), {
  84. username: this.props.user.username,
  85. last_click: this.props.status.last_click.fromNow()
  86. }, true);
  87. }
  88. }
  89. getLabel() {
  90. if (this.props.status.is_banned) {
  91. return gettext("Banned");
  92. } else if (this.props.status.is_hidden) {
  93. return gettext("Hidden");
  94. } else if (this.props.status.is_online_hidden) {
  95. return gettext("Online (hidden)");
  96. } else if (this.props.status.is_offline_hidden) {
  97. return gettext("Offline (hidden)");
  98. } else if (this.props.status.is_online) {
  99. return gettext("Online");
  100. } else if (this.props.status.is_offline) {
  101. return gettext("Offline");
  102. }
  103. }
  104. render() {
  105. /* jshint ignore:start */
  106. return <span className={this.props.className || "status-label"}
  107. title={this.getHelp()}>
  108. {this.getLabel()}
  109. </span>;
  110. /* jshint ignore:end */
  111. }
  112. }