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

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