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

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