您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

OverflowMenuProfileItem.js 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /* @flow */
  2. import React, { Component } from 'react';
  3. import { connect } from 'react-redux';
  4. import {
  5. Avatar,
  6. getAvatarURL,
  7. getLocalParticipant
  8. } from '../../../base/participants';
  9. declare var interfaceConfig: Object;
  10. /**
  11. * The type of the React {@code Component} props of
  12. * {@link OverflowMenuProfileItem}.
  13. */
  14. type Props = {
  15. /**
  16. * The redux representation of the local participant.
  17. */
  18. _localParticipant: Object,
  19. /**
  20. * Whether the button support clicking or not.
  21. */
  22. _unclickable: boolean,
  23. /**
  24. * The callback to invoke when {@code OverflowMenuProfileItem} is
  25. * clicked.
  26. */
  27. onClick: Function
  28. };
  29. /**
  30. * A React {@code Component} for displaying a link with a profile avatar as an
  31. * icon.
  32. *
  33. * @extends Component
  34. */
  35. class OverflowMenuProfileItem extends Component<Props> {
  36. /**
  37. * Initializes a new {@code OverflowMenuProfileItem} instance.
  38. *
  39. * @param {Object} props - The read-only properties with which the new
  40. * instance is to be initialized.
  41. */
  42. constructor(props: Props) {
  43. super(props);
  44. // Bind event handler so it is only bound once for every instance.
  45. this._onClick = this._onClick.bind(this);
  46. }
  47. /**
  48. * Implements React's {@link Component#render()}.
  49. *
  50. * @inheritdoc
  51. * @returns {ReactElement}
  52. */
  53. render() {
  54. const { _localParticipant, _unclickable } = this.props;
  55. const classNames = `overflow-menu-item ${
  56. _unclickable ? 'unclickable' : ''}`;
  57. const avatarURL = getAvatarURL(_localParticipant);
  58. let displayName;
  59. if (_localParticipant && _localParticipant.name) {
  60. displayName = _localParticipant.name;
  61. } else {
  62. displayName = interfaceConfig.DEFAULT_LOCAL_DISPLAY_NAME;
  63. }
  64. return (
  65. <li
  66. aria-label = 'Edit your profile'
  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. _onClick: () => void;
  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);