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

ProfileButton.js 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // @flow
  2. import { createToolbarEvent, sendAnalytics } from '../../../analytics';
  3. import { translate } from '../../../base/i18n';
  4. import { getLocalParticipant } from '../../../base/participants';
  5. import { connect } from '../../../base/redux';
  6. import { AbstractButton, type AbstractButtonProps } from '../../../base/toolbox/components';
  7. import { openSettingsDialog, SETTINGS_TABS } from '../../../settings';
  8. import ProfileButtonAvatar from './ProfileButtonAvatar';
  9. /**
  10. * The type of the React {@code Component} props of {@link ProfileButton}.
  11. */
  12. type Props = AbstractButtonProps & {
  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 redux {@code dispatch} function.
  23. */
  24. dispatch: Function
  25. };
  26. declare var interfaceConfig: Object;
  27. /**
  28. * Implementation of a button for opening profile dialog.
  29. */
  30. class ProfileButton extends AbstractButton<Props, *> {
  31. accessibilityLabel = 'toolbar.accessibilityLabel.profile';
  32. icon = ProfileButtonAvatar;
  33. /**
  34. * Retrieves the label.
  35. */
  36. get label() {
  37. const { _localParticipant } = this.props;
  38. let displayName;
  39. if (_localParticipant && _localParticipant.name) {
  40. displayName = _localParticipant.name;
  41. } else {
  42. displayName = interfaceConfig.DEFAULT_LOCAL_DISPLAY_NAME;
  43. }
  44. return displayName;
  45. }
  46. /**
  47. * Required by linter due to AbstractButton overwritten prop being writable.
  48. *
  49. * @param {string} value - The value.
  50. */
  51. set label(value) {
  52. return value;
  53. }
  54. /**
  55. * Retrieves the tooltip.
  56. */
  57. get tooltip() {
  58. return this.label;
  59. }
  60. /**
  61. * Required by linter due to AbstractButton overwritten prop being writable.
  62. *
  63. * @param {string} value - The value.
  64. */
  65. set tooltip(value) {
  66. return value;
  67. }
  68. /**
  69. * Handles clicking / pressing the button, and opens the appropriate dialog.
  70. *
  71. * @protected
  72. * @returns {void}
  73. */
  74. _handleClick() {
  75. const { dispatch, _unclickable, handleClick } = this.props;
  76. if (handleClick) {
  77. handleClick();
  78. return;
  79. }
  80. if (!_unclickable) {
  81. sendAnalytics(createToolbarEvent('profile'));
  82. dispatch(openSettingsDialog(SETTINGS_TABS.PROFILE));
  83. }
  84. }
  85. /**
  86. * Indicates whether the button should be disabled or not.
  87. *
  88. * @protected
  89. * @returns {void}
  90. */
  91. _isDisabled() {
  92. return this.props._unclickable;
  93. }
  94. }
  95. /**
  96. * Function that maps parts of Redux state tree into component props.
  97. *
  98. * @param {Object} state - Redux state.
  99. * @returns {Object}
  100. */
  101. const mapStateToProps = state => {
  102. return {
  103. _localParticipant: getLocalParticipant(state),
  104. _unclickable: !interfaceConfig.SETTINGS_SECTIONS.includes('profile'),
  105. customClass: 'profile-button-avatar'
  106. };
  107. };
  108. export default translate(connect(mapStateToProps)(ProfileButton));