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.js 2.5KB

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