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.web.js 3.5KB

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