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.tsx 12KB

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