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.2KB

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