Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

ReactionsMenuButton.js 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. // @flow
  2. import React, { useCallback } 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. const toggleReactionsMenu = useCallback(() => {
  67. dispatch(toggleReactionsMenuVisibility());
  68. }, [ dispatch ]);
  69. const raiseHandButton = (<ToolbarButton
  70. accessibilityLabel = { t('toolbar.accessibilityLabel.raiseHand') }
  71. icon = { IconRaisedHand }
  72. key = 'raise-hand'
  73. onClick = { handleClick }
  74. toggled = { raisedHand }
  75. tooltip = { t('toolbar.raiseHand') } />);
  76. return (
  77. <div className = 'reactions-menu-popup-container'>
  78. <ReactionsMenuPopup>
  79. {!_reactionsEnabled || isMobile ? raiseHandButton
  80. : (
  81. <ToolboxButtonWithIcon
  82. ariaControls = 'reactions-menu-dialog'
  83. ariaExpanded = { isOpen }
  84. ariaHasPopup = { true }
  85. ariaLabel = { t('toolbar.accessibilityLabel.reactionsMenu') }
  86. icon = { IconArrowUp }
  87. iconDisabled = { false }
  88. iconId = 'reactions-menu-button'
  89. iconTooltip = { t(`toolbar.${isOpen ? 'closeReactionsMenu' : 'openReactionsMenu'}`) }
  90. onIconClick = { toggleReactionsMenu }>
  91. {raiseHandButton}
  92. </ToolboxButtonWithIcon>
  93. )}
  94. </ReactionsMenuPopup>
  95. {reactionsQueue.map(({ reaction, uid }, index) => (<ReactionEmoji
  96. index = { index }
  97. key = { uid }
  98. reaction = { reaction }
  99. uid = { uid } />))}
  100. </div>
  101. );
  102. }
  103. /**
  104. * Function that maps parts of Redux state tree into component props.
  105. *
  106. * @param {Object} state - Redux state.
  107. * @returns {Object}
  108. */
  109. function mapStateToProps(state) {
  110. const localParticipant = getLocalParticipant(state);
  111. return {
  112. _reactionsEnabled: isReactionsEnabled(state),
  113. isOpen: getReactionsMenuVisibility(state),
  114. isMobile: isMobileBrowser(),
  115. reactionsQueue: getReactionsQueue(state),
  116. raisedHand: hasRaisedHand(localParticipant)
  117. };
  118. }
  119. export default translate(connect(mapStateToProps)(ReactionsMenuButton));