Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

OverflowMenu.tsx 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. import React, { PureComponent } from 'react';
  2. import { ViewStyle } from 'react-native';
  3. import { Divider } from 'react-native-paper';
  4. import { connect, useSelector } from 'react-redux';
  5. import { IReduxState, IStore } from '../../../app/types';
  6. import { hideSheet } from '../../../base/dialog/actions';
  7. import BottomSheet from '../../../base/dialog/components/native/BottomSheet';
  8. import { bottomSheetStyles } from '../../../base/dialog/components/native/styles';
  9. import SettingsButton from '../../../base/settings/components/native/SettingsButton';
  10. import BreakoutRoomsButton
  11. from '../../../breakout-rooms/components/native/BreakoutRoomsButton';
  12. import SharedDocumentButton from '../../../etherpad/components/SharedDocumentButton.native';
  13. import ReactionMenu from '../../../reactions/components/native/ReactionMenu';
  14. import { shouldDisplayReactionsButtons } from '../../../reactions/functions.any';
  15. import LiveStreamButton from '../../../recording/components/LiveStream/native/LiveStreamButton';
  16. import RecordButton from '../../../recording/components/Recording/native/RecordButton';
  17. import SecurityDialogButton
  18. from '../../../security/components/security-dialog/native/SecurityDialogButton';
  19. import SharedVideoButton from '../../../shared-video/components/native/SharedVideoButton';
  20. import { isSharedVideoEnabled } from '../../../shared-video/functions';
  21. import SpeakerStatsButton from '../../../speaker-stats/components/native/SpeakerStatsButton';
  22. import { isSpeakerStatsDisabled } from '../../../speaker-stats/functions';
  23. import ClosedCaptionButton from '../../../subtitles/components/native/ClosedCaptionButton';
  24. import styles from '../../../video-menu/components/native/styles';
  25. import WhiteboardButton from '../../../whiteboard/components/native/WhiteboardButton';
  26. import { customButtonPressed } from '../../actions.native';
  27. import { getVisibleNativeButtons } from '../../functions.native';
  28. import { useNativeToolboxButtons } from '../../hooks.native';
  29. import { IToolboxNativeButton } from '../../types';
  30. import AudioOnlyButton from './AudioOnlyButton';
  31. import LinkToSalesforceButton from './LinkToSalesforceButton';
  32. import OpenCarmodeButton from './OpenCarmodeButton';
  33. import RaiseHandButton from './RaiseHandButton';
  34. /**
  35. * The type of the React {@code Component} props of {@link OverflowMenu}.
  36. */
  37. interface IProps {
  38. /**
  39. * True if breakout rooms feature is available, false otherwise.
  40. */
  41. _isBreakoutRoomsSupported?: boolean;
  42. /**
  43. * True if the overflow menu is currently visible, false otherwise.
  44. */
  45. _isOpen: boolean;
  46. /**
  47. * Whether the shared video is enabled or not.
  48. */
  49. _isSharedVideoEnabled: boolean;
  50. /**
  51. * Whether or not speaker stats is disable.
  52. */
  53. _isSpeakerStatsDisabled?: boolean;
  54. /**
  55. * Toolbar buttons.
  56. */
  57. _mainMenuButtons?: Array<IToolboxNativeButton>;
  58. /**
  59. * Overflow menu buttons.
  60. */
  61. _overflowMenuButtons?: Array<IToolboxNativeButton>;
  62. /**
  63. * Whether the recoding button should be enabled or not.
  64. */
  65. _recordingEnabled: boolean;
  66. /**
  67. * Whether or not any reactions buttons should be displayed.
  68. */
  69. _shouldDisplayReactionsButtons: boolean;
  70. /**
  71. * Used for hiding the dialog when the selection was completed.
  72. */
  73. dispatch: IStore['dispatch'];
  74. }
  75. interface IState {
  76. /**
  77. * True if the bottom sheet is scrolled to the top.
  78. */
  79. scrolledToTop: boolean;
  80. }
  81. /**
  82. * Implements a React {@code Component} with some extra actions in addition to
  83. * those in the toolbar.
  84. */
  85. class OverflowMenu extends PureComponent<IProps, IState> {
  86. /**
  87. * Initializes a new {@code OverflowMenu} instance.
  88. *
  89. * @inheritdoc
  90. */
  91. constructor(props: IProps) {
  92. super(props);
  93. this.state = {
  94. scrolledToTop: true
  95. };
  96. // Bind event handlers so they are only bound once per instance.
  97. this._onCancel = this._onCancel.bind(this);
  98. this._renderReactionMenu = this._renderReactionMenu.bind(this);
  99. }
  100. /**
  101. * Implements React's {@link Component#render()}.
  102. *
  103. * @inheritdoc
  104. * @returns {ReactElement}
  105. */
  106. render() {
  107. const {
  108. _isBreakoutRoomsSupported,
  109. _isSpeakerStatsDisabled,
  110. _isSharedVideoEnabled,
  111. dispatch
  112. } = this.props;
  113. const buttonProps = {
  114. afterClick: this._onCancel,
  115. showLabel: true,
  116. styles: bottomSheetStyles.buttons
  117. };
  118. const topButtonProps = {
  119. afterClick: this._onCancel,
  120. dispatch,
  121. showLabel: true,
  122. styles: {
  123. ...bottomSheetStyles.buttons,
  124. style: {
  125. ...bottomSheetStyles.buttons.style,
  126. borderTopLeftRadius: 16,
  127. borderTopRightRadius: 16
  128. }
  129. }
  130. };
  131. return (
  132. <BottomSheet
  133. renderFooter = { this._renderReactionMenu }>
  134. <Divider style = { styles.divider as ViewStyle } />
  135. <OpenCarmodeButton { ...topButtonProps } />
  136. <AudioOnlyButton { ...buttonProps } />
  137. { this._renderRaiseHandButton(buttonProps) }
  138. {/* @ts-ignore */}
  139. <SecurityDialogButton { ...buttonProps } />
  140. <RecordButton { ...buttonProps } />
  141. <LiveStreamButton { ...buttonProps } />
  142. <LinkToSalesforceButton { ...buttonProps } />
  143. <WhiteboardButton { ...buttonProps } />
  144. {/* @ts-ignore */}
  145. <Divider style = { styles.divider as ViewStyle } />
  146. {_isSharedVideoEnabled && <SharedVideoButton { ...buttonProps } />}
  147. { this._renderOverflowMenuButtons(topButtonProps) }
  148. {!_isSpeakerStatsDisabled && <SpeakerStatsButton { ...buttonProps } />}
  149. {_isBreakoutRoomsSupported && <BreakoutRoomsButton { ...buttonProps } />}
  150. {/* @ts-ignore */}
  151. <Divider style = { styles.divider as ViewStyle } />
  152. <ClosedCaptionButton { ...buttonProps } />
  153. <SharedDocumentButton { ...buttonProps } />
  154. <SettingsButton { ...buttonProps } />
  155. </BottomSheet>
  156. );
  157. }
  158. /**
  159. * Hides this {@code OverflowMenu}.
  160. *
  161. * @private
  162. * @returns {void}
  163. */
  164. _onCancel() {
  165. this.props.dispatch(hideSheet());
  166. }
  167. /**
  168. * Function to render the reaction menu as the footer of the bottom sheet.
  169. *
  170. * @returns {React.ReactElement}
  171. */
  172. _renderReactionMenu() {
  173. const { _mainMenuButtons, _shouldDisplayReactionsButtons } = this.props;
  174. // @ts-ignore
  175. const isRaiseHandInMainMenu = _mainMenuButtons?.some(item => item.key === 'raisehand');
  176. if (_shouldDisplayReactionsButtons && !isRaiseHandInMainMenu) {
  177. return (
  178. <ReactionMenu
  179. onCancel = { this._onCancel }
  180. overflowMenu = { true } />
  181. );
  182. }
  183. }
  184. /**
  185. * Function to render the reaction menu as the footer of the bottom sheet.
  186. *
  187. * @param {Object} buttonProps - Styling button properties.
  188. * @returns {React.ReactElement}
  189. */
  190. _renderRaiseHandButton(buttonProps: Object) {
  191. const { _mainMenuButtons, _shouldDisplayReactionsButtons } = this.props;
  192. // @ts-ignore
  193. const isRaiseHandInMainMenu = _mainMenuButtons?.some(item => item.key === 'raisehand');
  194. if (!_shouldDisplayReactionsButtons && !isRaiseHandInMainMenu) {
  195. return (
  196. <RaiseHandButton { ...buttonProps } />
  197. );
  198. }
  199. }
  200. /**
  201. * Function to render the custom buttons for the overflow menu.
  202. *
  203. * @param {Object} topButtonProps - Styling button properties.
  204. * @returns {React.ReactElement}
  205. */
  206. _renderOverflowMenuButtons(topButtonProps: Object) {
  207. const { _overflowMenuButtons, dispatch } = this.props;
  208. if (!_overflowMenuButtons?.length) {
  209. return;
  210. }
  211. return (
  212. <>
  213. {
  214. _overflowMenuButtons?.map(({ Content, key, text, ...rest }: IToolboxNativeButton) => {
  215. if (key === 'raisehand') {
  216. return null;
  217. }
  218. return (
  219. <Content
  220. { ...topButtonProps }
  221. { ...rest }
  222. /* eslint-disable react/jsx-no-bind */
  223. handleClick = { () => dispatch(customButtonPressed(key, text)) }
  224. isToolboxButton = { false }
  225. key = { key }
  226. text = { text } />
  227. );
  228. })
  229. }
  230. <Divider style = { styles.divider as ViewStyle } />
  231. </>
  232. );
  233. }
  234. }
  235. /**
  236. * Function that maps parts of Redux state tree into component props.
  237. *
  238. * @param {Object} state - Redux state.
  239. * @private
  240. * @returns {IProps}
  241. */
  242. function _mapStateToProps(state: IReduxState) {
  243. const { conference } = state['features/base/conference'];
  244. return {
  245. _isBreakoutRoomsSupported: conference?.getBreakoutRooms()?.isSupported(),
  246. _isSharedVideoEnabled: isSharedVideoEnabled(state),
  247. _isSpeakerStatsDisabled: isSpeakerStatsDisabled(state),
  248. _shouldDisplayReactionsButtons: shouldDisplayReactionsButtons(state)
  249. };
  250. }
  251. export default connect(_mapStateToProps)(props => {
  252. const { clientWidth } = useSelector((state: IReduxState) => state['features/base/responsive-ui']);
  253. const { customToolbarButtons } = useSelector((state: IReduxState) => state['features/base/config']);
  254. const {
  255. mainToolbarButtonsThresholds,
  256. toolbarButtons
  257. } = useSelector((state: IReduxState) => state['features/toolbox']);
  258. const allButtons = useNativeToolboxButtons(customToolbarButtons);
  259. const { mainMenuButtons, overflowMenuButtons } = getVisibleNativeButtons({
  260. allButtons,
  261. clientWidth,
  262. mainToolbarButtonsThresholds,
  263. toolbarButtons
  264. });
  265. return (
  266. <OverflowMenu
  267. // @ts-ignore
  268. { ... props }
  269. _mainMenuButtons = { mainMenuButtons }
  270. _overflowMenuButtons = { overflowMenuButtons } />
  271. );
  272. });