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

ProfileButton.web.js 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /* @flow */
  2. import PropTypes from 'prop-types';
  3. import React, { Component } from 'react';
  4. import { connect } from 'react-redux';
  5. import { TOOLBAR_PROFILE_TOGGLED, sendAnalyticsEvent } from '../../analytics';
  6. import {
  7. getAvatarURL,
  8. getLocalParticipant
  9. } from '../../base/participants';
  10. import UIEvents from '../../../../service/UI/UIEvents';
  11. import ToolbarButton from './ToolbarButton';
  12. declare var APP: Object;
  13. /**
  14. * The default configuration for the button.
  15. *
  16. * @type {Object}
  17. */
  18. const DEFAULT_BUTTON_CONFIGURATION = {
  19. buttonName: 'profile',
  20. classNames: [ 'button' ],
  21. enabled: true,
  22. id: 'toolbar_button_profile',
  23. tooltipKey: 'profile.setDisplayNameLabel'
  24. };
  25. /**
  26. * React {@code Component} for the profile button.
  27. *
  28. * @extends Component
  29. */
  30. class ProfileButton extends Component<*> {
  31. _onClick: Function;
  32. /**
  33. * {@code ProfileButton}'s property types.
  34. *
  35. * @static
  36. */
  37. static propTypes = {
  38. /**
  39. * The redux representation of the local participant.
  40. */
  41. _localParticipant: PropTypes.object,
  42. /**
  43. * Whether the button support clicking or not.
  44. */
  45. _unclickable: PropTypes.bool,
  46. /**
  47. * Whether the side panel is opened or not.
  48. */
  49. toggled: PropTypes.bool,
  50. /**
  51. * From which side tooltips should display. Will be re-used for
  52. * displaying the inline dialog for video quality adjustment.
  53. */
  54. tooltipPosition: PropTypes.string
  55. };
  56. /**
  57. * Initializes a new {@code ProfileButton} instance.
  58. *
  59. * @param {Object} props - The read-only properties with which the new
  60. * instance is to be initialized.
  61. */
  62. constructor(props) {
  63. super(props);
  64. // Bind event handlers so they are only bound once for every instance.
  65. this._onClick = this._onClick.bind(this);
  66. }
  67. /**
  68. * Implements React's {@link Component#render()}.
  69. *
  70. * @inheritdoc
  71. * @returns {ReactElement}
  72. */
  73. render() {
  74. const {
  75. _localParticipant,
  76. _unclickable,
  77. tooltipPosition,
  78. toggled
  79. } = this.props;
  80. const buttonConfiguration = {
  81. ...DEFAULT_BUTTON_CONFIGURATION,
  82. unclickable: _unclickable,
  83. toggled
  84. };
  85. return (
  86. <ToolbarButton
  87. button = { buttonConfiguration }
  88. onClick = { this._onClick }
  89. tooltipPosition = { tooltipPosition }>
  90. <img
  91. id = 'avatar'
  92. src = { getAvatarURL(_localParticipant) } />
  93. </ToolbarButton>
  94. );
  95. }
  96. /**
  97. * Click handler for the button.
  98. *
  99. * @returns {void}
  100. */
  101. _onClick() {
  102. if (!this.props._unclickable) {
  103. sendAnalyticsEvent(TOOLBAR_PROFILE_TOGGLED);
  104. APP.UI.emitEvent(UIEvents.TOGGLE_PROFILE);
  105. }
  106. }
  107. }
  108. /**
  109. * Maps (parts of) the Redux state to the associated {@code ProfileButton}
  110. * component's props.
  111. *
  112. * @param {Object} state - The Redux state.
  113. * @private
  114. * @returns {{
  115. * _localParticipant: Object,
  116. * _unclickable: boolean
  117. * }}
  118. */
  119. function _mapStateToProps(state) {
  120. return {
  121. _localParticipant: getLocalParticipant(state),
  122. _unclickable: !state['features/base/jwt'].isGuest
  123. };
  124. }
  125. export default connect(_mapStateToProps)(ProfileButton);