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.

SettingsDialog.js 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  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
  235. = configuredTabs.includes('more') && (showLanguageSettings || showNotificationsSettings || showPrejoinSettings);
  236. const showProfileSettings
  237. = configuredTabs.includes('profile') && !state['features/base/config'].disableProfile;
  238. const showCalendarSettings
  239. = configuredTabs.includes('calendar') && isCalendarEnabled(state);
  240. const showSoundsSettings = configuredTabs.includes('sounds');
  241. const tabs = [];
  242. if (showDeviceSettings) {
  243. tabs.push({
  244. name: SETTINGS_TABS.DEVICES,
  245. component: DeviceSelection,
  246. label: 'settings.devices',
  247. onMount: getAvailableDevices,
  248. props: getDeviceSelectionDialogProps(state, isDisplayedOnWelcomePage),
  249. propsUpdateFunction: (tabState, newProps) => {
  250. // Ensure the device selection tab gets updated when new devices
  251. // are found by taking the new props and only preserving the
  252. // current user selected devices. If this were not done, the
  253. // tab would keep using a copy of the initial props it received,
  254. // leaving the device list to become stale.
  255. return {
  256. ...newProps,
  257. selectedAudioInputId: tabState.selectedAudioInputId,
  258. selectedAudioOutputId: tabState.selectedAudioOutputId,
  259. selectedVideoInputId: tabState.selectedVideoInputId
  260. };
  261. },
  262. styles: `settings-pane ${classes.settingsDialog} devices-pane`,
  263. submit: newState => submitDeviceSelectionTab(newState, isDisplayedOnWelcomePage)
  264. });
  265. }
  266. if (showProfileSettings) {
  267. tabs.push({
  268. name: SETTINGS_TABS.PROFILE,
  269. component: ProfileTab,
  270. label: 'profile.title',
  271. props: getProfileTabProps(state),
  272. styles: `settings-pane ${classes.settingsDialog} profile-pane`,
  273. submit: submitProfileTab
  274. });
  275. }
  276. if (showModeratorSettings) {
  277. tabs.push({
  278. name: SETTINGS_TABS.MODERATOR,
  279. component: ModeratorTab,
  280. label: 'settings.moderator',
  281. props: moderatorTabProps,
  282. propsUpdateFunction: (tabState, newProps) => {
  283. // Updates tab props, keeping users selection
  284. return {
  285. ...newProps,
  286. followMeEnabled: tabState?.followMeEnabled,
  287. startAudioMuted: tabState?.startAudioMuted,
  288. startVideoMuted: tabState?.startVideoMuted,
  289. startReactionsMuted: tabState?.startReactionsMuted
  290. };
  291. },
  292. styles: `settings-pane ${classes.settingsDialog} moderator-pane`,
  293. submit: submitModeratorTab
  294. });
  295. }
  296. if (showCalendarSettings) {
  297. tabs.push({
  298. name: SETTINGS_TABS.CALENDAR,
  299. component: CalendarTab,
  300. label: 'settings.calendar.title',
  301. styles: `settings-pane ${classes.settingsDialog} calendar-pane`
  302. });
  303. }
  304. if (showSoundsSettings) {
  305. tabs.push({
  306. name: SETTINGS_TABS.SOUNDS,
  307. component: SoundsTab,
  308. label: 'settings.sounds',
  309. props: getSoundsTabProps(state),
  310. styles: `settings-pane ${classes.settingsDialog} profile-pane`,
  311. submit: submitSoundsTab
  312. });
  313. }
  314. if (showMoreTab) {
  315. tabs.push({
  316. name: SETTINGS_TABS.MORE,
  317. component: MoreTab,
  318. label: 'settings.more',
  319. props: moreTabProps,
  320. propsUpdateFunction: (tabState, newProps) => {
  321. // Updates tab props, keeping users selection
  322. return {
  323. ...newProps,
  324. currentFramerate: tabState?.currentFramerate,
  325. currentLanguage: tabState?.currentLanguage,
  326. hideSelfView: tabState?.hideSelfView,
  327. showPrejoinPage: tabState?.showPrejoinPage,
  328. enabledNotifications: tabState?.enabledNotifications,
  329. maxStageParticipants: tabState?.maxStageParticipants
  330. };
  331. },
  332. styles: `settings-pane ${classes.settingsDialog} more-pane`,
  333. submit: submitMoreTab
  334. });
  335. }
  336. return { _tabs: tabs };
  337. }
  338. export default withStyles(styles)(connect(_mapStateToProps)(SettingsDialog));