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.

RaiseHandButton.ts 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 { RAISE_HAND_ENABLED } from '../../../base/flags/constants';
  6. import { getFeatureFlag } from '../../../base/flags/functions';
  7. import { translate } from '../../../base/i18n/functions';
  8. import { IconRaiseHand } from '../../../base/icons/svg';
  9. import { raiseHand } from '../../../base/participants/actions';
  10. import {
  11. getLocalParticipant,
  12. hasRaisedHand
  13. } from '../../../base/participants/functions';
  14. import { ILocalParticipant } from '../../../base/participants/types';
  15. import AbstractButton, { IProps as AbstractButtonProps } from '../../../base/toolbox/components/AbstractButton';
  16. /**
  17. * The type of the React {@code Component} props of {@link RaiseHandButton}.
  18. */
  19. interface IProps extends AbstractButtonProps {
  20. /**
  21. * The local participant.
  22. */
  23. _localParticipant?: ILocalParticipant;
  24. /**
  25. * Whether the participant raised their hand or not.
  26. */
  27. _raisedHand: boolean;
  28. }
  29. /**
  30. * An implementation of a button to raise or lower hand.
  31. */
  32. class RaiseHandButton extends AbstractButton<IProps> {
  33. accessibilityLabel = 'toolbar.accessibilityLabel.raiseHand';
  34. icon = IconRaiseHand;
  35. label = 'toolbar.raiseYourHand';
  36. toggledLabel = 'toolbar.lowerYourHand';
  37. /**
  38. * Handles clicking / pressing the button.
  39. *
  40. * @override
  41. * @protected
  42. * @returns {void}
  43. */
  44. _handleClick() {
  45. this._toggleRaisedHand();
  46. }
  47. /**
  48. * Indicates whether this button is in toggled state or not.
  49. *
  50. * @override
  51. * @protected
  52. * @returns {boolean}
  53. */
  54. _isToggled() {
  55. return this.props._raisedHand;
  56. }
  57. /**
  58. * Toggles the rased hand status of the local participant.
  59. *
  60. * @returns {void}
  61. */
  62. _toggleRaisedHand() {
  63. const enable = !this.props._raisedHand;
  64. sendAnalytics(createToolbarEvent('raise.hand', { enable }));
  65. this.props.dispatch(raiseHand(enable));
  66. }
  67. }
  68. /**
  69. * Maps part of the Redux state to the props of this component.
  70. *
  71. * @param {Object} state - The Redux state.
  72. * @param {Object} ownProps - The properties explicitly passed to the component instance.
  73. * @private
  74. * @returns {IProps}
  75. */
  76. function _mapStateToProps(state: IReduxState, ownProps: any) {
  77. const _localParticipant = getLocalParticipant(state);
  78. const enabled = getFeatureFlag(state, RAISE_HAND_ENABLED, true);
  79. const { visible = enabled } = ownProps;
  80. return {
  81. _localParticipant,
  82. _raisedHand: hasRaisedHand(_localParticipant),
  83. visible
  84. };
  85. }
  86. export default translate(connect(_mapStateToProps)(RaiseHandButton));