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.

ProfileButton.js 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 { SETTINGS_TABS, openSettingsDialog } 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. * Default displayed name for local participant.
  15. */
  16. _defaultLocalDisplayName: string,
  17. /**
  18. * The redux representation of the local participant.
  19. */
  20. _localParticipant: Object,
  21. /**
  22. * Whether the button support clicking or not.
  23. */
  24. _unclickable: boolean,
  25. /**
  26. * The redux {@code dispatch} function.
  27. */
  28. dispatch: Function
  29. };
  30. declare var interfaceConfig: Object;
  31. /**
  32. * Implementation of a button for opening profile dialog.
  33. */
  34. class ProfileButton extends AbstractButton<Props, *> {
  35. accessibilityLabel = 'toolbar.accessibilityLabel.profile';
  36. icon = ProfileButtonAvatar;
  37. /**
  38. * Retrieves the label.
  39. */
  40. get label() {
  41. const {
  42. _defaultLocalDisplayName,
  43. _localParticipant
  44. } = this.props;
  45. let displayName;
  46. if (_localParticipant?.name) {
  47. displayName = _localParticipant.name;
  48. } else {
  49. displayName = _defaultLocalDisplayName;
  50. }
  51. return displayName;
  52. }
  53. /**
  54. * Required by linter due to AbstractButton overwritten prop being writable.
  55. *
  56. * @param {string} _value - The value.
  57. */
  58. set label(_value) {
  59. // Unused.
  60. }
  61. /**
  62. * Retrieves the tooltip.
  63. */
  64. get tooltip() {
  65. return this.label;
  66. }
  67. /**
  68. * Required by linter due to AbstractButton overwritten prop being writable.
  69. *
  70. * @param {string} _value - The value.
  71. */
  72. set tooltip(_value) {
  73. // Unused.
  74. }
  75. /**
  76. * Handles clicking / pressing the button, and opens the appropriate dialog.
  77. *
  78. * @protected
  79. * @returns {void}
  80. */
  81. _handleClick() {
  82. const { dispatch, _unclickable } = this.props;
  83. if (!_unclickable) {
  84. sendAnalytics(createToolbarEvent('profile'));
  85. dispatch(openSettingsDialog(SETTINGS_TABS.PROFILE));
  86. }
  87. }
  88. /**
  89. * Indicates whether the button should be disabled or not.
  90. *
  91. * @protected
  92. * @returns {void}
  93. */
  94. _isDisabled() {
  95. return this.props._unclickable;
  96. }
  97. }
  98. /**
  99. * Function that maps parts of Redux state tree into component props.
  100. *
  101. * @param {Object} state - Redux state.
  102. * @returns {Object}
  103. */
  104. const mapStateToProps = state => {
  105. const { defaultLocalDisplayName } = state['features/base/config'];
  106. return {
  107. _defaultLocalDisplayName: defaultLocalDisplayName,
  108. _localParticipant: getLocalParticipant(state),
  109. _unclickable: !interfaceConfig.SETTINGS_SECTIONS.includes('profile'),
  110. customClass: 'profile-button-avatar'
  111. };
  112. };
  113. export default translate(connect(mapStateToProps)(ProfileButton));