您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ReactionsMenuButton.tsx 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. import React, { ReactElement, useCallback } from 'react';
  2. import { WithTranslation } from 'react-i18next';
  3. import { connect } from 'react-redux';
  4. import { IReduxState, IStore } from '../../../app/types';
  5. import { isMobileBrowser } from '../../../base/environment/utils';
  6. import { translate } from '../../../base/i18n/functions';
  7. import { IconArrowUp, IconFaceSmile } from '../../../base/icons/svg';
  8. import AbstractButton, { type IProps as AbstractButtonProps } from '../../../base/toolbox/components/AbstractButton';
  9. import ToolboxButtonWithPopup from '../../../base/toolbox/components/web/ToolboxButtonWithPopup';
  10. import { toggleReactionsMenuVisibility } from '../../actions.web';
  11. import { IReactionEmojiProps } from '../../constants';
  12. import { getReactionsQueue, isReactionsEnabled } from '../../functions.any';
  13. import { getReactionsMenuVisibility, isReactionsButtonEnabled } from '../../functions.web';
  14. import { IReactionsMenuParent } from '../../types';
  15. import RaiseHandButton from './RaiseHandButton';
  16. import ReactionEmoji from './ReactionEmoji';
  17. import ReactionsMenu from './ReactionsMenu';
  18. interface IProps extends WithTranslation {
  19. /**
  20. * Whether a mobile browser is used or not.
  21. */
  22. _isMobile: boolean;
  23. /**
  24. * Whether the reactions should be displayed on separate button or not.
  25. */
  26. _reactionsButtonEnabled: boolean;
  27. /**
  28. * The button's key.
  29. */
  30. buttonKey?: string;
  31. /**
  32. * Redux dispatch function.
  33. */
  34. dispatch: IStore['dispatch'];
  35. /**
  36. * Click handler for raise hand functionality.
  37. */
  38. handleClick: Function;
  39. /**
  40. * Whether or not it's narrow mode or mobile browser.
  41. */
  42. isNarrow: boolean;
  43. /**
  44. * Whether or not the reactions menu is open.
  45. */
  46. isOpen: boolean;
  47. /**
  48. * Notify mode for `toolbarButtonClicked` event -
  49. * whether to only notify or to also prevent button click routine.
  50. */
  51. notifyMode?: string;
  52. /**
  53. * The array of reactions to be displayed.
  54. */
  55. reactionsQueue: Array<IReactionEmojiProps>;
  56. }
  57. /**
  58. * Implementation of a button for reactions.
  59. */
  60. class ReactionsButtonImpl extends AbstractButton<AbstractButtonProps> {
  61. accessibilityLabel = 'toolbar.accessibilityLabel.reactions';
  62. icon = IconFaceSmile;
  63. label = 'toolbar.reactions';
  64. toggledLabel = 'toolbar.reactions';
  65. tooltip = 'toolbar.reactions';
  66. }
  67. const ReactionsButton = translate(connect()(ReactionsButtonImpl));
  68. /**
  69. * Button used for the reactions menu.
  70. *
  71. * @returns {ReactElement}
  72. */
  73. function ReactionsMenuButton({
  74. _reactionsButtonEnabled,
  75. _isMobile,
  76. buttonKey,
  77. dispatch,
  78. handleClick,
  79. isOpen,
  80. isNarrow,
  81. notifyMode,
  82. reactionsQueue,
  83. t
  84. }: IProps) {
  85. const toggleReactionsMenu = useCallback(() => {
  86. dispatch(toggleReactionsMenuVisibility());
  87. }, [ dispatch ]);
  88. const openReactionsMenu = useCallback(() => {
  89. !isOpen && toggleReactionsMenu();
  90. }, [ isOpen, toggleReactionsMenu ]);
  91. const closeReactionsMenu = useCallback(() => {
  92. isOpen && toggleReactionsMenu();
  93. }, [ isOpen, toggleReactionsMenu ]);
  94. const reactionsMenu = (<div className = 'reactions-menu-container'>
  95. <ReactionsMenu parent = { IReactionsMenuParent.Button } />
  96. </div>);
  97. let content: ReactElement | null = null;
  98. if (_reactionsButtonEnabled) {
  99. content = (
  100. <ToolboxButtonWithPopup
  101. ariaLabel = { t('toolbar.accessibilityLabel.reactionsMenu') }
  102. onPopoverClose = { closeReactionsMenu }
  103. onPopoverOpen = { openReactionsMenu }
  104. popoverContent = { reactionsMenu }
  105. trigger = { _isMobile ? 'click' : undefined }
  106. visible = { isOpen }>
  107. <ReactionsButton
  108. buttonKey = { buttonKey }
  109. notifyMode = { notifyMode } />
  110. </ToolboxButtonWithPopup>);
  111. } else {
  112. content = isNarrow
  113. ? (
  114. <RaiseHandButton
  115. buttonKey = { buttonKey }
  116. handleClick = { handleClick }
  117. notifyMode = { notifyMode } />)
  118. : (
  119. <ToolboxButtonWithPopup
  120. ariaLabel = { t('toolbar.accessibilityLabel.reactionsMenu') }
  121. icon = { IconArrowUp }
  122. iconDisabled = { false }
  123. onPopoverClose = { toggleReactionsMenu }
  124. onPopoverOpen = { openReactionsMenu }
  125. popoverContent = { reactionsMenu }
  126. visible = { isOpen }>
  127. <RaiseHandButton
  128. buttonKey = { buttonKey }
  129. handleClick = { handleClick }
  130. notifyMode = { notifyMode } />
  131. </ToolboxButtonWithPopup>);
  132. }
  133. return (
  134. <div className = 'reactions-menu-popup-container'>
  135. { content }
  136. {reactionsQueue.map(({ reaction, uid }, index) => (<ReactionEmoji
  137. index = { index }
  138. key = { uid }
  139. reaction = { reaction }
  140. uid = { uid } />))}
  141. </div>
  142. );
  143. }
  144. /**
  145. * Function that maps parts of Redux state tree into component props.
  146. *
  147. * @param {Object} state - Redux state.
  148. * @returns {Object}
  149. */
  150. function mapStateToProps(state: IReduxState) {
  151. const { isNarrowLayout } = state['features/base/responsive-ui'];
  152. return {
  153. _reactionsButtonEnabled: isReactionsButtonEnabled(state),
  154. _reactionsEnabled: isReactionsEnabled(state),
  155. _isMobile: isMobileBrowser(),
  156. isOpen: getReactionsMenuVisibility(state),
  157. isNarrow: isNarrowLayout,
  158. reactionsQueue: getReactionsQueue(state)
  159. };
  160. }
  161. export default translate(connect(mapStateToProps)(ReactionsMenuButton));