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.js 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. aria-label = 'Edit your profile'
  68. className = { classNames }
  69. onClick = { this._onClick }>
  70. <span className = 'overflow-menu-item-icon'>
  71. <Avatar uri = { avatarURL } />
  72. </span>
  73. <span className = 'profile-text'>
  74. { displayName }
  75. </span>
  76. </li>
  77. );
  78. }
  79. /**
  80. * Invokes an on click callback if clicking is allowed.
  81. *
  82. * @returns {void}
  83. */
  84. _onClick() {
  85. if (!this.props._unclickable) {
  86. this.props.onClick();
  87. }
  88. }
  89. }
  90. /**
  91. * Maps (parts of) the Redux state to the associated
  92. * {@code OverflowMenuProfileItem} component's props.
  93. *
  94. * @param {Object} state - The Redux state.
  95. * @private
  96. * @returns {{
  97. * _localParticipant: Object,
  98. * _unclickable: boolean
  99. * }}
  100. */
  101. function _mapStateToProps(state) {
  102. return {
  103. _localParticipant: getLocalParticipant(state),
  104. _unclickable: !state['features/base/jwt'].isGuest
  105. || !interfaceConfig.SETTINGS_SECTIONS.includes('profile')
  106. };
  107. }
  108. export default connect(_mapStateToProps)(OverflowMenuProfileItem);