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

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