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

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