您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ReactionsMenu.js 6.6KB

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