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.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import { connect } from 'react-redux';
  2. import { createToolbarEvent } from '../../../analytics/AnalyticsEvents';
  3. import { sendAnalytics } from '../../../analytics/functions';
  4. import { IReduxState, IStore } from '../../../app/types';
  5. import { translate } from '../../../base/i18n/functions';
  6. import { IconRaiseHand } from '../../../base/icons/svg';
  7. import { raiseHand } from '../../../base/participants/actions';
  8. import { getLocalParticipant, hasRaisedHand } from '../../../base/participants/functions';
  9. import AbstractButton, { IProps as AbstractButtonProps } from '../../../base/toolbox/components/AbstractButton';
  10. /**
  11. * The type of the React {@code Component} props of {@link RaiseHandButton}.
  12. */
  13. interface IProps extends AbstractButtonProps {
  14. /**
  15. * Whether or not the click is disabled.
  16. */
  17. disableClick?: boolean;
  18. /**
  19. * Redux dispatch function.
  20. */
  21. dispatch: IStore['dispatch'];
  22. /**
  23. * Whether or not the hand is raised.
  24. */
  25. raisedHand: boolean;
  26. }
  27. /**
  28. * Implementation of a button for raising hand.
  29. */
  30. class RaiseHandButton extends AbstractButton<IProps> {
  31. accessibilityLabel = 'toolbar.accessibilityLabel.raiseHand';
  32. toggledAccessibilityLabel = 'toolbar.accessibilityLabel.lowerHand';
  33. icon = IconRaiseHand;
  34. label = 'toolbar.raiseHand';
  35. toggledLabel = 'toolbar.lowerYourHand';
  36. tooltip = 'toolbar.raiseHand';
  37. toggledTooltip = 'toolbar.lowerYourHand';
  38. /**
  39. * Indicates whether this button is in toggled state or not.
  40. *
  41. * @override
  42. * @protected
  43. * @returns {boolean}
  44. */
  45. _isToggled() {
  46. return this.props.raisedHand;
  47. }
  48. /**
  49. * Handles clicking the button, and toggles the raise hand.
  50. *
  51. * @private
  52. * @returns {void}
  53. */
  54. _handleClick() {
  55. const { disableClick, dispatch, raisedHand } = this.props;
  56. if (disableClick) {
  57. return;
  58. }
  59. sendAnalytics(createToolbarEvent(
  60. 'raise.hand',
  61. { enable: !raisedHand }));
  62. dispatch(raiseHand(!raisedHand));
  63. }
  64. }
  65. /**
  66. * Function that maps parts of Redux state tree into component props.
  67. *
  68. * @param {Object} state - Redux state.
  69. * @returns {Object}
  70. */
  71. const mapStateToProps = (state: IReduxState) => {
  72. const localParticipant = getLocalParticipant(state);
  73. return {
  74. raisedHand: hasRaisedHand(localParticipant)
  75. };
  76. };
  77. export { RaiseHandButton };
  78. export default translate(connect(mapStateToProps)(RaiseHandButton));