Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

ReactionsMenu.js 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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. const { dispatch, _raisedHand } = this.props;
  91. sendAnalytics(createToolbarEvent(
  92. 'raise.hand',
  93. { enable: !_raisedHand }));
  94. this._doToggleRaiseHand();
  95. dispatch(toggleReactionsMenuVisibility());
  96. }
  97. /**
  98. * Dispatches an action to toggle the local participant's raised hand state.
  99. *
  100. * @private
  101. * @returns {void}
  102. */
  103. _doToggleRaiseHand() {
  104. const { _localParticipantID, _raisedHand } = this.props;
  105. const newRaisedStatus = !_raisedHand;
  106. this.props.dispatch(participantUpdated({
  107. // XXX Only the local participant is allowed to update without
  108. // stating the JitsiConference instance (i.e. participant property
  109. // `conference` for a remote participant) because the local
  110. // participant is uniquely identified by the very fact that there is
  111. // only one local participant.
  112. id: _localParticipantID,
  113. local: true,
  114. raisedHand: newRaisedStatus
  115. }));
  116. APP.API.notifyRaiseHandUpdated(_localParticipantID, newRaisedStatus);
  117. }
  118. /**
  119. * Returns the emoji reaction buttons.
  120. *
  121. * @returns {Array}
  122. */
  123. _getReactionButtons() {
  124. const { t, dispatch } = this.props;
  125. let modifierKey = 'Alt';
  126. if (window.navigator?.platform) {
  127. if (window.navigator.platform.indexOf('Mac') !== -1) {
  128. modifierKey = '⌥';
  129. }
  130. }
  131. return Object.keys(REACTIONS).map(key => {
  132. /**
  133. * Sends reaction message.
  134. *
  135. * @returns {void}
  136. */
  137. function doSendReaction() {
  138. dispatch(addReactionToBuffer(key));
  139. sendAnalytics(createReactionMenuEvent(key));
  140. }
  141. return (<ReactionButton
  142. accessibilityLabel = { t(`toolbar.accessibilityLabel.${key}`) }
  143. icon = { REACTIONS[key].emoji }
  144. key = { key }
  145. onClick = { doSendReaction }
  146. toggled = { false }
  147. tooltip = { `${t(`toolbar.${key}`)} (${modifierKey} + ${REACTIONS[key].shortcutChar})` } />);
  148. });
  149. }
  150. /**
  151. * Implements React's {@link Component#render}.
  152. *
  153. * @inheritdoc
  154. */
  155. render() {
  156. const { _participantCount, _raisedHand, t, overflowMenu } = this.props;
  157. return (
  158. <div className = { `reactions-menu ${overflowMenu ? 'overflow' : ''}` }>
  159. { _participantCount > 1 && <div className = 'reactions-row'>
  160. { this._getReactionButtons() }
  161. </div> }
  162. <div className = 'raise-hand-row'>
  163. <ReactionButton
  164. accessibilityLabel = { t('toolbar.accessibilityLabel.raiseHand') }
  165. icon = '✋'
  166. key = 'raisehand'
  167. label = {
  168. `${t(`toolbar.${_raisedHand ? 'lowerYourHand' : 'raiseYourHand'}`)}
  169. ${overflowMenu ? '' : ' (R)'}`
  170. }
  171. onClick = { this._onToolbarToggleRaiseHand }
  172. toggled = { true } />
  173. </div>
  174. </div>
  175. );
  176. }
  177. }
  178. /**
  179. * Function that maps parts of Redux state tree into component props.
  180. *
  181. * @param {Object} state - Redux state.
  182. * @returns {Object}
  183. */
  184. function mapStateToProps(state) {
  185. const localParticipant = getLocalParticipant(state);
  186. return {
  187. _localParticipantID: localParticipant.id,
  188. _raisedHand: localParticipant.raisedHand,
  189. _participantCount: getParticipantCount(state)
  190. };
  191. }
  192. /**
  193. * Function that maps parts of Redux actions into component props.
  194. *
  195. * @param {Object} dispatch - Redux dispatch.
  196. * @returns {Object}
  197. */
  198. function mapDispatchToProps(dispatch) {
  199. return {
  200. dispatch,
  201. ...bindActionCreators(
  202. {
  203. _dockToolbox: dockToolbox
  204. }, dispatch)
  205. };
  206. }
  207. export default translate(connect(
  208. mapStateToProps,
  209. mapDispatchToProps,
  210. )(ReactionsMenu));