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

ReactionsMenuButton.js 4.4KB

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