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

ReactionsMenuButton.tsx 4.4KB

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