Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

ReactionsMenu.tsx 7.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. /* eslint-disable import/order */
  2. import { withStyles } from '@material-ui/styles';
  3. import clsx from 'clsx';
  4. import React, { Component } from 'react';
  5. import { bindActionCreators } from 'redux';
  6. import {
  7. createReactionMenuEvent,
  8. createToolbarEvent,
  9. sendAnalytics
  10. // @ts-ignore
  11. } from '../../../analytics';
  12. import { IStore } from '../../../app/types';
  13. // @ts-ignore
  14. import { isMobileBrowser } from '../../../base/environment/utils';
  15. // @ts-ignore
  16. import { translate } from '../../../base/i18n';
  17. // @ts-ignore
  18. import { getLocalParticipant, hasRaisedHand, raiseHand } from '../../../base/participants';
  19. // @ts-ignore
  20. import { connect } from '../../../base/redux';
  21. // @ts-ignore
  22. import { GifsMenu, GifsMenuButton } from '../../../gifs/components';
  23. // @ts-ignore
  24. import { isGifEnabled, isGifsMenuOpen } from '../../../gifs/functions';
  25. // @ts-ignore
  26. import { dockToolbox } from '../../../toolbox/actions.web';
  27. import { addReactionToBuffer } from '../../actions.any';
  28. import { toggleReactionsMenuVisibility } from '../../actions.web';
  29. import { REACTIONS, REACTIONS_MENU_HEIGHT } from '../../constants';
  30. // @ts-ignore
  31. import ReactionButton from './ReactionButton';
  32. interface Classes {
  33. overflow: string
  34. }
  35. type Props = {
  36. /**
  37. * Docks the toolbox.
  38. */
  39. _dockToolbox: Function,
  40. /**
  41. * Whether or not the GIF feature is enabled.
  42. */
  43. _isGifEnabled: boolean,
  44. /**
  45. * Whether or not the GIF menu is visible.
  46. */
  47. _isGifMenuVisible: boolean,
  48. /**
  49. * Whether or not it's a mobile browser.
  50. */
  51. _isMobile: boolean,
  52. /**
  53. * The ID of the local participant.
  54. */
  55. _localParticipantID: String,
  56. /**
  57. * Whether or not the local participant's hand is raised.
  58. */
  59. _raisedHand: boolean,
  60. /**
  61. * An object containing the CSS classes.
  62. */
  63. classes: Classes,
  64. /**
  65. * The Redux Dispatch function.
  66. */
  67. dispatch: Function,
  68. /**
  69. * Whether or not it's displayed in the overflow menu.
  70. */
  71. overflowMenu: boolean,
  72. /**
  73. * Used for translation.
  74. */
  75. t: Function
  76. };
  77. const styles = (theme: any) => {
  78. return {
  79. overflow: {
  80. width: 'auto',
  81. paddingBottom: 'max(env(safe-area-inset-bottom, 0), 16px)',
  82. backgroundColor: theme.palette.ui01,
  83. boxShadow: 'none',
  84. borderRadius: 0,
  85. position: 'relative',
  86. boxSizing: 'border-box',
  87. height: `${REACTIONS_MENU_HEIGHT}px`
  88. }
  89. };
  90. };
  91. /**
  92. * Implements the reactions menu.
  93. *
  94. * @returns {ReactElement}
  95. */
  96. class ReactionsMenu extends Component<Props> {
  97. /**
  98. * Initializes a new {@code ReactionsMenu} instance.
  99. *
  100. * @param {Props} props - The read-only React {@code Component} props with
  101. * which the new instance is to be initialized.
  102. */
  103. constructor(props: Props) {
  104. super(props);
  105. this._onToolbarToggleRaiseHand = this._onToolbarToggleRaiseHand.bind(this);
  106. this._getReactionButtons = this._getReactionButtons.bind(this);
  107. }
  108. /**
  109. * Implements React Component's componentDidMount.
  110. *
  111. * @inheritdoc
  112. */
  113. componentDidMount() {
  114. this.props._dockToolbox(true);
  115. }
  116. /**
  117. * Implements React Component's componentWillUnmount.
  118. *
  119. * @inheritdoc
  120. */
  121. componentWillUnmount() {
  122. this.props._dockToolbox(false);
  123. }
  124. /**
  125. * Creates an analytics toolbar event and dispatches an action for toggling
  126. * raise hand.
  127. *
  128. * @returns {void}
  129. */
  130. _onToolbarToggleRaiseHand() {
  131. const { dispatch, _raisedHand } = this.props;
  132. sendAnalytics(createToolbarEvent(
  133. 'raise.hand',
  134. { enable: !_raisedHand }));
  135. this._doToggleRaiseHand();
  136. dispatch(toggleReactionsMenuVisibility());
  137. }
  138. /**
  139. * Dispatches an action to toggle the local participant's raised hand state.
  140. *
  141. * @private
  142. * @returns {void}
  143. */
  144. _doToggleRaiseHand() {
  145. const { _raisedHand } = this.props;
  146. this.props.dispatch(raiseHand(!_raisedHand));
  147. }
  148. /**
  149. * Returns the emoji reaction buttons.
  150. *
  151. * @returns {Array}
  152. */
  153. _getReactionButtons() {
  154. const { t, dispatch } = this.props;
  155. let modifierKey = 'Alt';
  156. if (window.navigator?.platform) {
  157. if (window.navigator.platform.indexOf('Mac') !== -1) {
  158. modifierKey = '⌥';
  159. }
  160. }
  161. return Object.keys(REACTIONS).map(key => {
  162. /**
  163. * Sends reaction message.
  164. *
  165. * @returns {void}
  166. */
  167. function doSendReaction() {
  168. dispatch(addReactionToBuffer(key));
  169. sendAnalytics(createReactionMenuEvent(key));
  170. }
  171. // @ts-ignore
  172. return (<ReactionButton
  173. accessibilityLabel = { t(`toolbar.accessibilityLabel.${key}`) }
  174. icon = { REACTIONS[key].emoji }
  175. key = { key }
  176. // eslint-disable-next-line react/jsx-no-bind
  177. onClick = { doSendReaction }
  178. toggled = { false }
  179. tooltip = { `${t(`toolbar.${key}`)} (${modifierKey} + ${REACTIONS[key].shortcutChar})` } />);
  180. });
  181. }
  182. /**
  183. * Implements React's {@link Component#render}.
  184. *
  185. * @inheritdoc
  186. */
  187. render() {
  188. const { _raisedHand, t, overflowMenu, _isMobile, classes, _isGifMenuVisible, _isGifEnabled } = this.props;
  189. return (
  190. <div
  191. className = { clsx('reactions-menu', _isGifEnabled && 'with-gif',
  192. overflowMenu && `overflow ${classes.overflow}`) }>
  193. {_isGifEnabled && _isGifMenuVisible && <GifsMenu />}
  194. <div className = 'reactions-row'>
  195. { this._getReactionButtons() }
  196. {_isGifEnabled && <GifsMenuButton />}
  197. </div>
  198. {_isMobile && (
  199. <div className = 'raise-hand-row'>
  200. {/* @ts-ignore */}
  201. <ReactionButton
  202. accessibilityLabel = { t('toolbar.accessibilityLabel.raiseHand') }
  203. icon = '✋'
  204. key = 'raisehand'
  205. label = {
  206. `${t(`toolbar.${_raisedHand ? 'lowerYourHand' : 'raiseYourHand'}`)}
  207. ${overflowMenu ? '' : ' (R)'}`
  208. }
  209. onClick = { this._onToolbarToggleRaiseHand }
  210. toggled = { true } />
  211. </div>
  212. )}
  213. </div>
  214. );
  215. }
  216. }
  217. /**
  218. * Function that maps parts of Redux state tree into component props.
  219. *
  220. * @param {Object} state - Redux state.
  221. * @returns {Object}
  222. */
  223. function mapStateToProps(state: any) {
  224. const localParticipant = getLocalParticipant(state);
  225. return {
  226. _localParticipantID: localParticipant.id,
  227. _isMobile: isMobileBrowser(),
  228. _isGifEnabled: isGifEnabled(state),
  229. _isGifMenuVisible: isGifsMenuOpen(state),
  230. _raisedHand: hasRaisedHand(localParticipant)
  231. };
  232. }
  233. /**
  234. * Function that maps parts of Redux actions into component props.
  235. *
  236. * @param {Object} dispatch - Redux dispatch.
  237. * @returns {Object}
  238. */
  239. function mapDispatchToProps(dispatch: IStore['dispatch']) {
  240. return {
  241. dispatch,
  242. ...bindActionCreators(
  243. {
  244. _dockToolbox: dockToolbox
  245. // @ts-ignore
  246. }, dispatch)
  247. };
  248. }
  249. export default translate(connect(
  250. mapStateToProps,
  251. mapDispatchToProps
  252. // @ts-ignore
  253. )(withStyles(styles)(ReactionsMenu)));