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.

ReactionsMenu.js 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. // @flow
  2. import React, { Component } from 'react';
  3. import { bindActionCreators } from 'redux';
  4. import {
  5. createReactionMenuEvent,
  6. createToolbarEvent,
  7. sendAnalytics
  8. } from '../../../analytics';
  9. import { isMobileBrowser } from '../../../base/environment/utils';
  10. import { translate } from '../../../base/i18n';
  11. import { getLocalParticipant, hasRaisedHand, raiseHand } from '../../../base/participants';
  12. import { connect } from '../../../base/redux';
  13. import { dockToolbox } from '../../../toolbox/actions.web';
  14. import { addReactionToBuffer } from '../../actions.any';
  15. import { toggleReactionsMenuVisibility } from '../../actions.web';
  16. import { REACTIONS } from '../../constants';
  17. import ReactionButton from './ReactionButton';
  18. type Props = {
  19. /**
  20. * Docks the toolbox
  21. */
  22. _dockToolbox: Function,
  23. /**
  24. * Whether or not it's a mobile browser.
  25. */
  26. _isMobile: boolean,
  27. /**
  28. * The ID of the local participant.
  29. */
  30. _localParticipantID: String,
  31. /**
  32. * Whether or not the local participant's hand is raised.
  33. */
  34. _raisedHand: boolean,
  35. /**
  36. * The Redux Dispatch function.
  37. */
  38. dispatch: Function,
  39. /**
  40. * Whether or not it's displayed in the overflow menu.
  41. */
  42. overflowMenu: boolean,
  43. /**
  44. * Used for translation.
  45. */
  46. t: Function
  47. };
  48. declare var APP: Object;
  49. /**
  50. * Implements the reactions menu.
  51. *
  52. * @returns {ReactElement}
  53. */
  54. class ReactionsMenu extends Component<Props> {
  55. /**
  56. * Initializes a new {@code ReactionsMenu} instance.
  57. *
  58. * @param {Props} props - The read-only React {@code Component} props with
  59. * which the new instance is to be initialized.
  60. */
  61. constructor(props: Props) {
  62. super(props);
  63. this._onToolbarToggleRaiseHand = this._onToolbarToggleRaiseHand.bind(this);
  64. this._getReactionButtons = this._getReactionButtons.bind(this);
  65. }
  66. _onToolbarToggleRaiseHand: () => void;
  67. _getReactionButtons: () => Array<React$Element<*>>;
  68. /**
  69. * Implements React Component's componentDidMount.
  70. *
  71. * @inheritdoc
  72. */
  73. componentDidMount() {
  74. this.props._dockToolbox(true);
  75. }
  76. /**
  77. * Implements React Component's componentWillUnmount.
  78. *
  79. * @inheritdoc
  80. */
  81. componentWillUnmount() {
  82. this.props._dockToolbox(false);
  83. }
  84. /**
  85. * Creates an analytics toolbar event and dispatches an action for toggling
  86. * raise hand.
  87. *
  88. * @returns {void}
  89. */
  90. _onToolbarToggleRaiseHand() {
  91. const { dispatch, _raisedHand } = this.props;
  92. sendAnalytics(createToolbarEvent(
  93. 'raise.hand',
  94. { enable: !_raisedHand }));
  95. this._doToggleRaiseHand();
  96. dispatch(toggleReactionsMenuVisibility());
  97. }
  98. /**
  99. * Dispatches an action to toggle the local participant's raised hand state.
  100. *
  101. * @private
  102. * @returns {void}
  103. */
  104. _doToggleRaiseHand() {
  105. const { _raisedHand } = this.props;
  106. this.props.dispatch(raiseHand(!_raisedHand));
  107. }
  108. /**
  109. * Returns the emoji reaction buttons.
  110. *
  111. * @returns {Array}
  112. */
  113. _getReactionButtons() {
  114. const { t, dispatch } = this.props;
  115. let modifierKey = 'Alt';
  116. if (window.navigator?.platform) {
  117. if (window.navigator.platform.indexOf('Mac') !== -1) {
  118. modifierKey = '⌥';
  119. }
  120. }
  121. return Object.keys(REACTIONS).map(key => {
  122. /**
  123. * Sends reaction message.
  124. *
  125. * @returns {void}
  126. */
  127. function doSendReaction() {
  128. dispatch(addReactionToBuffer(key));
  129. sendAnalytics(createReactionMenuEvent(key));
  130. }
  131. return (<ReactionButton
  132. accessibilityLabel = { t(`toolbar.accessibilityLabel.${key}`) }
  133. icon = { REACTIONS[key].emoji }
  134. key = { key }
  135. onClick = { doSendReaction }
  136. toggled = { false }
  137. tooltip = { `${t(`toolbar.${key}`)} (${modifierKey} + ${REACTIONS[key].shortcutChar})` } />);
  138. });
  139. }
  140. /**
  141. * Implements React's {@link Component#render}.
  142. *
  143. * @inheritdoc
  144. */
  145. render() {
  146. const { _raisedHand, t, overflowMenu, _isMobile } = this.props;
  147. return (
  148. <div className = { `reactions-menu ${overflowMenu ? 'overflow' : ''}` }>
  149. <div className = 'reactions-row'>
  150. { this._getReactionButtons() }
  151. </div>
  152. {_isMobile && (
  153. <div className = 'raise-hand-row'>
  154. <ReactionButton
  155. accessibilityLabel = { t('toolbar.accessibilityLabel.raiseHand') }
  156. icon = '✋'
  157. key = 'raisehand'
  158. label = {
  159. `${t(`toolbar.${_raisedHand ? 'lowerYourHand' : 'raiseYourHand'}`)}
  160. ${overflowMenu ? '' : ' (R)'}`
  161. }
  162. onClick = { this._onToolbarToggleRaiseHand }
  163. toggled = { true } />
  164. </div>
  165. )}
  166. </div>
  167. );
  168. }
  169. }
  170. /**
  171. * Function that maps parts of Redux state tree into component props.
  172. *
  173. * @param {Object} state - Redux state.
  174. * @returns {Object}
  175. */
  176. function mapStateToProps(state) {
  177. const localParticipant = getLocalParticipant(state);
  178. return {
  179. _localParticipantID: localParticipant.id,
  180. _isMobile: isMobileBrowser(),
  181. _raisedHand: hasRaisedHand(localParticipant)
  182. };
  183. }
  184. /**
  185. * Function that maps parts of Redux actions into component props.
  186. *
  187. * @param {Object} dispatch - Redux dispatch.
  188. * @returns {Object}
  189. */
  190. function mapDispatchToProps(dispatch) {
  191. return {
  192. dispatch,
  193. ...bindActionCreators(
  194. {
  195. _dockToolbox: dockToolbox
  196. }, dispatch)
  197. };
  198. }
  199. export default translate(connect(
  200. mapStateToProps,
  201. mapDispatchToProps,
  202. )(ReactionsMenu));