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.

MoreTab.js 8.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. // @flow
  2. import { Checkbox } from '@atlaskit/checkbox';
  3. import DropdownMenu, {
  4. DropdownItem,
  5. DropdownItemGroup
  6. } from '@atlaskit/dropdown-menu';
  7. import React from 'react';
  8. import { AbstractDialogTab } from '../../../base/dialog';
  9. import type { Props as AbstractDialogTabProps } from '../../../base/dialog';
  10. import { translate } from '../../../base/i18n';
  11. import TouchmoveHack from '../../../chat/components/web/TouchmoveHack';
  12. /**
  13. * The type of the React {@code Component} props of {@link MoreTab}.
  14. */
  15. export type Props = {
  16. ...$Exact<AbstractDialogTabProps>,
  17. /**
  18. * The currently selected language to display in the language select
  19. * dropdown.
  20. */
  21. currentLanguage: string,
  22. /**
  23. * Whether or not follow me is currently active (enabled by some other participant).
  24. */
  25. followMeActive: boolean,
  26. /**
  27. * Whether or not the user has selected the Follow Me feature to be enabled.
  28. */
  29. followMeEnabled: boolean,
  30. /**
  31. * All available languages to display in the language select dropdown.
  32. */
  33. languages: Array<string>,
  34. /**
  35. * Whether or not to display the language select dropdown.
  36. */
  37. showLanguageSettings: boolean,
  38. /**
  39. * Whether or not to display moderator-only settings.
  40. */
  41. showModeratorSettings: boolean,
  42. /**
  43. * Whether or not to display the prejoin settings section.
  44. */
  45. showPrejoinSettings: boolean,
  46. /**
  47. * Whether or not to show prejoin screen.
  48. */
  49. showPrejoinPage: boolean,
  50. /**
  51. * Whether or not the user has selected the Start Audio Muted feature to be
  52. * enabled.
  53. */
  54. startAudioMuted: boolean,
  55. /**
  56. * Whether or not the user has selected the Start Video Muted feature to be
  57. * enabled.
  58. */
  59. startVideoMuted: boolean,
  60. /**
  61. * Invoked to obtain translated strings.
  62. */
  63. t: Function
  64. };
  65. /**
  66. * The type of the React {@code Component} state of {@link MoreTab}.
  67. */
  68. type State = {
  69. /**
  70. * Whether or not the language select dropdown is open.
  71. */
  72. isLanguageSelectOpen: boolean
  73. };
  74. /**
  75. * React {@code Component} for modifying language and moderator settings.
  76. *
  77. * @extends Component
  78. */
  79. class MoreTab extends AbstractDialogTab<Props, State> {
  80. /**
  81. * Initializes a new {@code MoreTab} instance.
  82. *
  83. * @param {Object} props - The read-only properties with which the new
  84. * instance is to be initialized.
  85. */
  86. constructor(props: Props) {
  87. super(props);
  88. this.state = {
  89. isLanguageSelectOpen: false
  90. };
  91. // Bind event handler so it is only bound once for every instance.
  92. this._onLanguageDropdownOpenChange
  93. = this._onLanguageDropdownOpenChange.bind(this);
  94. }
  95. /**
  96. * Implements React's {@link Component#render()}.
  97. *
  98. * @inheritdoc
  99. * @returns {ReactElement}
  100. */
  101. render() {
  102. const { showModeratorSettings, showLanguageSettings, showPrejoinSettings } = this.props;
  103. const content = [];
  104. if (showPrejoinSettings) {
  105. content.push(this._renderPrejoinScreenSettings());
  106. }
  107. if (showModeratorSettings) {
  108. content.push(this._renderModeratorSettings());
  109. }
  110. if (showLanguageSettings) {
  111. content.push(this._renderLangaugeSelect());
  112. }
  113. return <div className = 'more-tab'>{ content }</div>;
  114. }
  115. _onLanguageDropdownOpenChange: (Object) => void;
  116. /**
  117. * Callback invoked to toggle display of the language select dropdown.
  118. *
  119. * @param {Object} event - The event for opening or closing the dropdown.
  120. * @private
  121. * @returns {void}
  122. */
  123. _onLanguageDropdownOpenChange({ isOpen }) {
  124. this.setState({ isLanguageSelectOpen: isOpen });
  125. }
  126. /**
  127. * Returns the menu item for changing displayed language.
  128. *
  129. * @private
  130. * @returns {ReactElement}
  131. */
  132. _renderLangaugeSelect() {
  133. const {
  134. currentLanguage,
  135. languages,
  136. t
  137. } = this.props;
  138. const languageItems
  139. = languages.map(language => (
  140. <DropdownItem
  141. key = { language }
  142. // eslint-disable-next-line react/jsx-no-bind
  143. onClick = {
  144. e => {
  145. e.stopPropagation();
  146. super._onChange({ currentLanguage: language });
  147. }
  148. }>
  149. { t(`languages:${language}`) }
  150. </DropdownItem>));
  151. return (
  152. <div
  153. className = 'settings-sub-pane language-settings'
  154. key = 'language'>
  155. <div className = 'mock-atlaskit-label'>
  156. { t('settings.language') }
  157. </div>
  158. <div className = 'dropdown-menu'>
  159. <TouchmoveHack isModal = { true }>
  160. <DropdownMenu
  161. isOpen = { this.state.isLanguageSelectOpen }
  162. onOpenChange = { this._onLanguageDropdownOpenChange }
  163. shouldFitContainer = { true }
  164. trigger = { currentLanguage
  165. ? t(`languages:${currentLanguage}`)
  166. : '' }
  167. triggerButtonProps = {{
  168. shouldFitContainer: true
  169. }}
  170. triggerType = 'button'>
  171. <DropdownItemGroup>
  172. { languageItems }
  173. </DropdownItemGroup>
  174. </DropdownMenu>
  175. </TouchmoveHack>
  176. </div>
  177. </div>
  178. );
  179. }
  180. /**
  181. * Returns the React Element for modifying conference-wide settings.
  182. *
  183. * @private
  184. * @returns {ReactElement}
  185. */
  186. _renderModeratorSettings() {
  187. const {
  188. followMeActive,
  189. followMeEnabled,
  190. startAudioMuted,
  191. startVideoMuted,
  192. t
  193. } = this.props;
  194. return (
  195. <div
  196. className = 'settings-sub-pane'
  197. key = 'moderator'>
  198. <div className = 'mock-atlaskit-label'>
  199. { t('settings.moderator') }
  200. </div>
  201. <Checkbox
  202. isChecked = { startAudioMuted }
  203. label = { t('settings.startAudioMuted') }
  204. name = 'start-audio-muted'
  205. // eslint-disable-next-line react/jsx-no-bind
  206. onChange = {
  207. ({ target: { checked } }) =>
  208. super._onChange({ startAudioMuted: checked })
  209. } />
  210. <Checkbox
  211. isChecked = { startVideoMuted }
  212. label = { t('settings.startVideoMuted') }
  213. name = 'start-video-muted'
  214. // eslint-disable-next-line react/jsx-no-bind
  215. onChange = {
  216. ({ target: { checked } }) =>
  217. super._onChange({ startVideoMuted: checked })
  218. } />
  219. <Checkbox
  220. isChecked = { followMeEnabled && !followMeActive }
  221. isDisabled = { followMeActive }
  222. label = { t('settings.followMe') }
  223. name = 'follow-me'
  224. // eslint-disable-next-line react/jsx-no-bind
  225. onChange = {
  226. ({ target: { checked } }) =>
  227. super._onChange({ followMeEnabled: checked })
  228. } />
  229. </div>
  230. );
  231. }
  232. /**
  233. * Returns the React Element for modifying prejoin screen settings.
  234. *
  235. * @private
  236. * @returns {ReactElement}
  237. */
  238. _renderPrejoinScreenSettings() {
  239. const { t, showPrejoinPage } = this.props;
  240. return (
  241. <div
  242. className = 'settings-sub-pane'
  243. key = 'prejoin-screen'>
  244. <div className = 'mock-atlaskit-label'>
  245. { t('prejoin.premeeting') }
  246. </div>
  247. <Checkbox
  248. isChecked = { showPrejoinPage }
  249. label = { t('prejoin.showScreen') }
  250. name = 'show-prejoin-page'
  251. // eslint-disable-next-line react/jsx-no-bind
  252. onChange = {
  253. ({ target: { checked } }) =>
  254. super._onChange({ showPrejoinPage: checked })
  255. } />
  256. </div>
  257. );
  258. }
  259. }
  260. export default translate(MoreTab);