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.

ReactionsMenuButton.tsx 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /* eslint-disable lines-around-comment */
  2. import React, { useCallback } from 'react';
  3. import { WithTranslation } from 'react-i18next';
  4. import { useSelector } from 'react-redux';
  5. import { IReduxState } from '../../../app/types';
  6. import { isMobileBrowser } from '../../../base/environment/utils';
  7. import { translate } from '../../../base/i18n/functions';
  8. import { IconArrowUp } from '../../../base/icons/svg';
  9. import { connect } from '../../../base/redux/functions';
  10. // @ts-ignore
  11. import ToolboxButtonWithIconPopup from '../../../base/toolbox/components/web/ToolboxButtonWithIconPopup';
  12. import { toggleReactionsMenuVisibility } from '../../actions.web';
  13. import { IReactionEmojiProps } from '../../constants';
  14. import { getReactionsQueue, isReactionsEnabled } from '../../functions.any';
  15. import { getReactionsMenuVisibility } from '../../functions.web';
  16. // @ts-ignore
  17. import RaiseHandButton from './RaiseHandButton';
  18. import ReactionEmoji from './ReactionEmoji';
  19. import ReactionsMenu from './ReactionsMenu';
  20. interface IProps extends WithTranslation {
  21. /**
  22. * Whether or not reactions are enabled.
  23. */
  24. _reactionsEnabled: Boolean;
  25. /**
  26. * The button's key.
  27. */
  28. buttonKey?: string;
  29. /**
  30. * Redux dispatch function.
  31. */
  32. dispatch: Function;
  33. /**
  34. * Click handler for raise hand functionality.
  35. */
  36. handleClick: Function;
  37. /**
  38. * Whether or not it's a mobile browser.
  39. */
  40. isMobile: boolean;
  41. /**
  42. * Whether or not the reactions menu is open.
  43. */
  44. isOpen: boolean;
  45. /**
  46. * Notify mode for `toolbarButtonClicked` event -
  47. * whether to only notify or to also prevent button click routine.
  48. */
  49. notifyMode?: string;
  50. /**
  51. * The array of reactions to be displayed.
  52. */
  53. reactionsQueue: Array<IReactionEmojiProps>;
  54. }
  55. /**
  56. * Button used for the reactions menu.
  57. *
  58. * @returns {ReactElement}
  59. */
  60. function ReactionsMenuButton({
  61. _reactionsEnabled,
  62. buttonKey,
  63. dispatch,
  64. handleClick,
  65. isOpen,
  66. isMobile,
  67. notifyMode,
  68. reactionsQueue,
  69. t
  70. }: IProps) {
  71. const visible = useSelector(getReactionsMenuVisibility);
  72. const toggleReactionsMenu = useCallback(() => {
  73. dispatch(toggleReactionsMenuVisibility());
  74. }, [ dispatch ]);
  75. const openReactionsMenu = useCallback(() => {
  76. !visible && toggleReactionsMenu();
  77. }, [ visible, toggleReactionsMenu ]);
  78. const reactionsMenu = (<div className = 'reactions-menu-container'>
  79. <ReactionsMenu />
  80. </div>);
  81. return (
  82. <div className = 'reactions-menu-popup-container'>
  83. {!_reactionsEnabled || isMobile ? (
  84. <RaiseHandButton
  85. buttonKey = { buttonKey }
  86. handleClick = { handleClick }
  87. notifyMode = { notifyMode } />)
  88. : (
  89. <ToolboxButtonWithIconPopup
  90. ariaControls = 'reactions-menu-dialog'
  91. ariaExpanded = { isOpen }
  92. ariaHasPopup = { true }
  93. ariaLabel = { t('toolbar.accessibilityLabel.reactionsMenu') }
  94. icon = { IconArrowUp }
  95. iconDisabled = { false }
  96. iconId = 'reactions-menu-button'
  97. onPopoverClose = { toggleReactionsMenu }
  98. onPopoverOpen = { openReactionsMenu }
  99. popoverContent = { reactionsMenu }
  100. visible = { visible }>
  101. <RaiseHandButton
  102. buttonKey = { buttonKey }
  103. handleClick = { handleClick }
  104. notifyMode = { notifyMode } />
  105. </ToolboxButtonWithIconPopup>
  106. )}
  107. {reactionsQueue.map(({ reaction, uid }, index) => (<ReactionEmoji
  108. index = { index }
  109. key = { uid }
  110. reaction = { reaction }
  111. uid = { uid } />))}
  112. </div>
  113. );
  114. }
  115. /**
  116. * Function that maps parts of Redux state tree into component props.
  117. *
  118. * @param {Object} state - Redux state.
  119. * @returns {Object}
  120. */
  121. function mapStateToProps(state: IReduxState) {
  122. return {
  123. _reactionsEnabled: isReactionsEnabled(state),
  124. isOpen: getReactionsMenuVisibility(state),
  125. isMobile: isMobileBrowser(),
  126. reactionsQueue: getReactionsQueue(state)
  127. };
  128. }
  129. export default translate(connect(mapStateToProps)(ReactionsMenuButton));