Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

ReactionsMenu.js 6.1KB

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