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

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