Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

SettingsDialog.js 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. // @flow
  2. import { withStyles } from '@material-ui/styles';
  3. import React, { Component } from 'react';
  4. import { getAvailableDevices } from '../../../base/devices';
  5. import { DialogWithTabs, hideDialog } from '../../../base/dialog';
  6. import { connect } from '../../../base/redux';
  7. import { isCalendarEnabled } from '../../../calendar-sync';
  8. import {
  9. DeviceSelection,
  10. getDeviceSelectionDialogProps,
  11. submitDeviceSelectionTab
  12. } from '../../../device-selection';
  13. import {
  14. submitModeratorTab,
  15. submitMoreTab,
  16. submitProfileTab,
  17. submitSoundsTab
  18. } from '../../actions';
  19. import { SETTINGS_TABS } from '../../constants';
  20. import {
  21. getModeratorTabProps,
  22. getMoreTabProps,
  23. getProfileTabProps,
  24. getSoundsTabProps
  25. } from '../../functions';
  26. import CalendarTab from './CalendarTab';
  27. import ModeratorTab from './ModeratorTab';
  28. import MoreTab from './MoreTab';
  29. import ProfileTab from './ProfileTab';
  30. import SoundsTab from './SoundsTab';
  31. declare var interfaceConfig: Object;
  32. /**
  33. * The type of the React {@code Component} props of
  34. * {@link ConnectedSettingsDialog}.
  35. */
  36. type Props = {
  37. /**
  38. * An object containing the CSS classes.
  39. */
  40. classes: Object,
  41. /**
  42. * Which settings tab should be initially displayed. If not defined then
  43. * the first tab will be displayed.
  44. */
  45. defaultTab: string,
  46. /**
  47. * Information about the tabs to be rendered.
  48. */
  49. _tabs: Array<Object>,
  50. /**
  51. * Invoked to save changed settings.
  52. */
  53. dispatch: Function,
  54. /**
  55. * Indicates whether the device selection dialog is displayed on the
  56. * welcome page or not.
  57. */
  58. isDisplayedOnWelcomePage: boolean
  59. };
  60. /**
  61. * Creates the styles for the component.
  62. *
  63. * @param {Object} theme - The current UI theme.
  64. *
  65. * @returns {Object}
  66. */
  67. const styles = theme => {
  68. return {
  69. settingsDialog: {
  70. display: 'flex',
  71. width: '100%',
  72. '&.profile-pane': {
  73. flexDirection: 'column'
  74. },
  75. '& .auth-name': {
  76. marginBottom: `${theme.spacing(1)}px`
  77. },
  78. '& .calendar-tab, & .device-selection': {
  79. marginTop: '20px'
  80. },
  81. '& .mock-atlaskit-label': {
  82. color: '#b8c7e0',
  83. fontSize: '12px',
  84. fontWeight: 600,
  85. lineHeight: 1.33,
  86. padding: `20px 0px ${theme.spacing(1)}px 0px`
  87. },
  88. '& input[type="checkbox"]:checked + svg': {
  89. '--checkbox-background-color': '#6492e7',
  90. '--checkbox-border-color': '#6492e7'
  91. },
  92. '& input[type="checkbox"] + svg + span': {
  93. color: '#9FB0CC'
  94. },
  95. [[ '& .calendar-tab',
  96. '& .more-tab',
  97. '& .box' ]]: {
  98. display: 'flex',
  99. justifyContent: 'space-between',
  100. width: '100%'
  101. },
  102. '& .profile-edit': {
  103. display: 'flex',
  104. width: '100%'
  105. },
  106. '& .profile-edit-field': {
  107. flex: 0.5,
  108. marginRight: '20px'
  109. },
  110. '& .settings-sub-pane': {
  111. flex: 1
  112. },
  113. '& .settings-sub-pane .right': {
  114. flex: 1
  115. },
  116. '& .settings-sub-pane .left': {
  117. flex: 1
  118. },
  119. '& .settings-sub-pane-element': {
  120. textAlign: 'left',
  121. flex: 1
  122. },
  123. '& .moderator-settings-wrapper': {
  124. paddingTop: '20px'
  125. },
  126. '& .calendar-tab': {
  127. alignItems: 'center',
  128. flexDirection: 'column',
  129. fontSize: '14px',
  130. minHeight: '100px',
  131. textAlign: 'center'
  132. },
  133. '& .calendar-tab-sign-in': {
  134. marginTop: '20px'
  135. },
  136. '& .sign-out-cta': {
  137. marginBottom: '20px'
  138. },
  139. '@media only screen and (max-width: 700px)': {
  140. '& .device-selection': {
  141. display: 'flex',
  142. flexDirection: 'column'
  143. },
  144. '& .more-tab': {
  145. flexDirection: 'column'
  146. }
  147. }
  148. }
  149. };
  150. };
  151. /**
  152. * A React {@code Component} for displaying a dialog to modify local settings
  153. * and conference-wide (moderator) settings. This version is connected to
  154. * redux to get the current settings.
  155. *
  156. * @augments Component
  157. */
  158. class SettingsDialog extends Component<Props> {
  159. /**
  160. * Initializes a new {@code ConnectedSettingsDialog} instance.
  161. *
  162. * @param {Props} props - The React {@code Component} props to initialize
  163. * the new {@code ConnectedSettingsDialog} instance with.
  164. */
  165. constructor(props: Props) {
  166. super(props);
  167. // Bind event handlers so they are only bound once for every instance.
  168. this._closeDialog = this._closeDialog.bind(this);
  169. }
  170. /**
  171. * Implements React's {@link Component#render()}.
  172. *
  173. * @inheritdoc
  174. * @returns {ReactElement}
  175. */
  176. render() {
  177. const { _tabs, defaultTab, dispatch } = this.props;
  178. const onSubmit = this._closeDialog;
  179. const defaultTabIdx
  180. = _tabs.findIndex(({ name }) => name === defaultTab);
  181. const tabs = _tabs.map(tab => {
  182. return {
  183. ...tab,
  184. onMount: tab.onMount
  185. ? (...args) => dispatch(tab.onMount(...args))
  186. : undefined,
  187. submit: (...args) => tab.submit
  188. && dispatch(tab.submit(...args))
  189. };
  190. });
  191. return (
  192. <DialogWithTabs
  193. closeDialog = { this._closeDialog }
  194. cssClassName = 'settings-dialog'
  195. defaultTab = {
  196. defaultTabIdx === -1 ? undefined : defaultTabIdx
  197. }
  198. onSubmit = { onSubmit }
  199. tabs = { tabs }
  200. titleKey = 'settings.title' />
  201. );
  202. }
  203. _closeDialog: () => void;
  204. /**
  205. * Callback invoked to close the dialog without saving changes.
  206. *
  207. * @private
  208. * @returns {void}
  209. */
  210. _closeDialog() {
  211. this.props.dispatch(hideDialog());
  212. }
  213. }
  214. /**
  215. * Maps (parts of) the Redux state to the associated props for the
  216. * {@code ConnectedSettingsDialog} component.
  217. *
  218. * @param {Object} state - The Redux state.
  219. * @param {Object} ownProps - The props passed to the component.
  220. * @private
  221. * @returns {{
  222. * tabs: Array<Object>
  223. * }}
  224. */
  225. function _mapStateToProps(state, ownProps) {
  226. const { classes, isDisplayedOnWelcomePage } = ownProps;
  227. const configuredTabs = interfaceConfig.SETTINGS_SECTIONS || [];
  228. // The settings sections to display.
  229. const showDeviceSettings = configuredTabs.includes('devices');
  230. const moreTabProps = getMoreTabProps(state);
  231. const moderatorTabProps = getModeratorTabProps(state);
  232. const { showModeratorSettings } = moderatorTabProps;
  233. const { showLanguageSettings, showNotificationsSettings, showPrejoinSettings } = moreTabProps;
  234. const showMoreTab = showLanguageSettings || showNotificationsSettings || showPrejoinSettings;
  235. const showProfileSettings
  236. = configuredTabs.includes('profile') && !state['features/base/config'].disableProfile;
  237. const showCalendarSettings
  238. = configuredTabs.includes('calendar') && isCalendarEnabled(state);
  239. const showSoundsSettings = configuredTabs.includes('sounds');
  240. const tabs = [];
  241. if (showDeviceSettings) {
  242. tabs.push({
  243. name: SETTINGS_TABS.DEVICES,
  244. component: DeviceSelection,
  245. label: 'settings.devices',
  246. onMount: getAvailableDevices,
  247. props: getDeviceSelectionDialogProps(state, isDisplayedOnWelcomePage),
  248. propsUpdateFunction: (tabState, newProps) => {
  249. // Ensure the device selection tab gets updated when new devices
  250. // are found by taking the new props and only preserving the
  251. // current user selected devices. If this were not done, the
  252. // tab would keep using a copy of the initial props it received,
  253. // leaving the device list to become stale.
  254. return {
  255. ...newProps,
  256. selectedAudioInputId: tabState.selectedAudioInputId,
  257. selectedAudioOutputId: tabState.selectedAudioOutputId,
  258. selectedVideoInputId: tabState.selectedVideoInputId
  259. };
  260. },
  261. styles: `settings-pane ${classes.settingsDialog} devices-pane`,
  262. submit: newState => submitDeviceSelectionTab(newState, isDisplayedOnWelcomePage)
  263. });
  264. }
  265. if (showProfileSettings) {
  266. tabs.push({
  267. name: SETTINGS_TABS.PROFILE,
  268. component: ProfileTab,
  269. label: 'profile.title',
  270. props: getProfileTabProps(state),
  271. styles: `settings-pane ${classes.settingsDialog} profile-pane`,
  272. submit: submitProfileTab
  273. });
  274. }
  275. if (showModeratorSettings) {
  276. tabs.push({
  277. name: SETTINGS_TABS.MODERATOR,
  278. component: ModeratorTab,
  279. label: 'settings.moderator',
  280. props: moderatorTabProps,
  281. propsUpdateFunction: (tabState, newProps) => {
  282. // Updates tab props, keeping users selection
  283. return {
  284. ...newProps,
  285. followMeEnabled: tabState?.followMeEnabled,
  286. startAudioMuted: tabState?.startAudioMuted,
  287. startVideoMuted: tabState?.startVideoMuted,
  288. startReactionsMuted: tabState?.startReactionsMuted
  289. };
  290. },
  291. styles: `settings-pane ${classes.settingsDialog} moderator-pane`,
  292. submit: submitModeratorTab
  293. });
  294. }
  295. if (showCalendarSettings) {
  296. tabs.push({
  297. name: SETTINGS_TABS.CALENDAR,
  298. component: CalendarTab,
  299. label: 'settings.calendar.title',
  300. styles: `settings-pane ${classes.settingsDialog} calendar-pane`
  301. });
  302. }
  303. if (showSoundsSettings) {
  304. tabs.push({
  305. name: SETTINGS_TABS.SOUNDS,
  306. component: SoundsTab,
  307. label: 'settings.sounds',
  308. props: getSoundsTabProps(state),
  309. styles: `settings-pane ${classes.settingsDialog} profile-pane`,
  310. submit: submitSoundsTab
  311. });
  312. }
  313. if (showMoreTab) {
  314. tabs.push({
  315. name: SETTINGS_TABS.MORE,
  316. component: MoreTab,
  317. label: 'settings.more',
  318. props: moreTabProps,
  319. propsUpdateFunction: (tabState, newProps) => {
  320. // Updates tab props, keeping users selection
  321. return {
  322. ...newProps,
  323. currentFramerate: tabState?.currentFramerate,
  324. currentLanguage: tabState?.currentLanguage,
  325. hideSelfView: tabState?.hideSelfView,
  326. showPrejoinPage: tabState?.showPrejoinPage,
  327. enabledNotifications: tabState?.enabledNotifications,
  328. maxStageParticipants: tabState?.maxStageParticipants
  329. };
  330. },
  331. styles: `settings-pane ${classes.settingsDialog} more-pane`,
  332. submit: submitMoreTab
  333. });
  334. }
  335. return { _tabs: tabs };
  336. }
  337. export default withStyles(styles)(connect(_mapStateToProps)(SettingsDialog));