You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

OverflowMenuProfileItem.web.js 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /* globals interfaceConfig */
  2. import PropTypes from 'prop-types';
  3. import React, { Component } from 'react';
  4. import { connect } from 'react-redux';
  5. import {
  6. Avatar,
  7. getAvatarURL,
  8. getLocalParticipant
  9. } from '../../base/participants';
  10. /**
  11. * A React {@code Component} for displaying a link with a profile avatar as an
  12. * icon.
  13. *
  14. * @extends Component
  15. */
  16. class OverflowMenuProfileItem extends Component {
  17. /**
  18. * {@code OverflowMenuProfileItem}'s property types.
  19. *
  20. * @static
  21. */
  22. static propTypes = {
  23. /**
  24. * The redux representation of the local participant.
  25. */
  26. _localParticipant: PropTypes.object,
  27. /**
  28. * Whether the button support clicking or not.
  29. */
  30. _unclickable: PropTypes.bool,
  31. /**
  32. * The callback to invoke when {@code OverflowMenuProfileItem} is
  33. * clicked.
  34. */
  35. onClick: PropTypes.func
  36. };
  37. /**
  38. * Initializes a new {@code OverflowMenuProfileItem} instance.
  39. *
  40. * @param {Object} props - The read-only properties with which the new
  41. * instance is to be initialized.
  42. */
  43. constructor(props) {
  44. super(props);
  45. // Bind event handler so it is only bound once for every instance.
  46. this._onClick = this._onClick.bind(this);
  47. }
  48. /**
  49. * Implements React's {@link Component#render()}.
  50. *
  51. * @inheritdoc
  52. * @returns {ReactElement}
  53. */
  54. render() {
  55. const { _localParticipant, _unclickable } = this.props;
  56. const classNames = `overflow-menu-item ${
  57. _unclickable ? 'unclickable' : ''}`;
  58. const avatarURL = getAvatarURL(_localParticipant);
  59. let displayName;
  60. if (_localParticipant && _localParticipant.name) {
  61. displayName = _localParticipant.name.split(' ')[0];
  62. } else {
  63. displayName = interfaceConfig.DEFAULT_LOCAL_DISPLAY_NAME;
  64. }
  65. return (
  66. <li
  67. className = { classNames }
  68. onClick = { this._onClick }>
  69. <span className = 'overflow-menu-item-icon'>
  70. <Avatar uri = { avatarURL } />
  71. </span>
  72. <span className = 'profile-text'>
  73. { displayName }
  74. </span>
  75. </li>
  76. );
  77. }
  78. /**
  79. * Invokes an on click callback if clicking is allowed.
  80. *
  81. * @returns {void}
  82. */
  83. _onClick() {
  84. if (!this.props._unclickable) {
  85. this.props.onClick();
  86. }
  87. }
  88. }
  89. /**
  90. * Maps (parts of) the Redux state to the associated
  91. * {@code OverflowMenuProfileItem} component's props.
  92. *
  93. * @param {Object} state - The Redux state.
  94. * @private
  95. * @returns {{
  96. * _localParticipant: Object,
  97. * _unclickable: boolean
  98. * }}
  99. */
  100. function _mapStateToProps(state) {
  101. return {
  102. _localParticipant: getLocalParticipant(state),
  103. _unclickable: !state['features/base/jwt'].isGuest
  104. };
  105. }
  106. export default connect(_mapStateToProps)(OverflowMenuProfileItem);