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.js 4.1KB

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