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.tsx 7.7KB

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