Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

ProfileButton.ts 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import { connect } from 'react-redux';
  2. import { createToolbarEvent } from '../../../analytics/AnalyticsEvents';
  3. import { sendAnalytics } from '../../../analytics/functions';
  4. import { IReduxState } from '../../../app/types';
  5. import { translate } from '../../../base/i18n/functions';
  6. import { getLocalParticipant } from '../../../base/participants/functions';
  7. import { ILocalParticipant } from '../../../base/participants/types';
  8. import AbstractButton, { IProps as AbstractButtonProps } from '../../../base/toolbox/components/AbstractButton';
  9. import { openSettingsDialog } from '../../../settings/actions';
  10. import { SETTINGS_TABS } from '../../../settings/constants';
  11. import ProfileButtonAvatar from './ProfileButtonAvatar';
  12. /**
  13. * The type of the React {@code Component} props of {@link ProfileButton}.
  14. */
  15. interface IProps extends AbstractButtonProps {
  16. /**
  17. * Default displayed name for local participant.
  18. */
  19. _defaultLocalDisplayName: string;
  20. /**
  21. * The redux representation of the local participant.
  22. */
  23. _localParticipant?: ILocalParticipant;
  24. /**
  25. * Whether the button support clicking or not.
  26. */
  27. _unclickable: boolean;
  28. }
  29. /**
  30. * Implementation of a button for opening profile dialog.
  31. */
  32. class ProfileButton extends AbstractButton<IProps> {
  33. accessibilityLabel = 'toolbar.accessibilityLabel.profile';
  34. icon = ProfileButtonAvatar;
  35. /**
  36. * Retrieves the label.
  37. *
  38. * @returns {string}
  39. */
  40. _getLabel() {
  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. * Retrieves the tooltip.
  55. *
  56. * @returns {string}
  57. */
  58. _getTooltip() {
  59. return this._getLabel();
  60. }
  61. /**
  62. * Handles clicking / pressing the button, and opens the appropriate dialog.
  63. *
  64. * @protected
  65. * @returns {void}
  66. */
  67. _handleClick() {
  68. const { dispatch, _unclickable } = this.props;
  69. if (!_unclickable) {
  70. sendAnalytics(createToolbarEvent('profile'));
  71. dispatch(openSettingsDialog(SETTINGS_TABS.PROFILE));
  72. }
  73. }
  74. /**
  75. * Indicates whether the button should be disabled or not.
  76. *
  77. * @protected
  78. * @returns {void}
  79. */
  80. _isDisabled() {
  81. return this.props._unclickable;
  82. }
  83. }
  84. /**
  85. * Function that maps parts of Redux state tree into component props.
  86. *
  87. * @param {Object} state - Redux state.
  88. * @returns {Object}
  89. */
  90. const mapStateToProps = (state: IReduxState) => {
  91. const { defaultLocalDisplayName } = state['features/base/config'];
  92. return {
  93. _defaultLocalDisplayName: defaultLocalDisplayName ?? '',
  94. _localParticipant: getLocalParticipant(state),
  95. _unclickable: !interfaceConfig.SETTINGS_SECTIONS.includes('profile'),
  96. customClass: 'profile-button-avatar'
  97. };
  98. };
  99. export default translate(connect(mapStateToProps)(ProfileButton));