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

ReactionsMenuButton.js 4.1KB

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