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 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. // @flow
  2. import React, { Component } from 'react';
  3. import { getAvailableDevices } from '../../../base/devices';
  4. import { DialogWithTabs, hideDialog } from '../../../base/dialog';
  5. import { connect } from '../../../base/redux';
  6. import { isCalendarEnabled } from '../../../calendar-sync';
  7. import {
  8. DeviceSelection,
  9. getDeviceSelectionDialogProps,
  10. submitDeviceSelectionTab
  11. } from '../../../device-selection';
  12. import { submitMoreTab, submitProfileTab } from '../../actions';
  13. import { SETTINGS_TABS } from '../../constants';
  14. import { getMoreTabProps, getProfileTabProps } from '../../functions';
  15. import CalendarTab from './CalendarTab';
  16. import MoreTab from './MoreTab';
  17. import ProfileTab from './ProfileTab';
  18. declare var APP: Object;
  19. declare var interfaceConfig: Object;
  20. /**
  21. * The type of the React {@code Component} props of
  22. * {@link ConnectedSettingsDialog}.
  23. */
  24. type Props = {
  25. /**
  26. * Which settings tab should be initially displayed. If not defined then
  27. * the first tab will be displayed.
  28. */
  29. defaultTab: string,
  30. /**
  31. * Information about the tabs to be rendered.
  32. */
  33. _tabs: Array<Object>,
  34. /**
  35. * Invoked to save changed settings.
  36. */
  37. dispatch: Function
  38. };
  39. /**
  40. * A React {@code Component} for displaying a dialog to modify local settings
  41. * and conference-wide (moderator) settings. This version is connected to
  42. * redux to get the current settings.
  43. *
  44. * @extends Component
  45. */
  46. class SettingsDialog extends Component<Props> {
  47. /**
  48. * Initializes a new {@code ConnectedSettingsDialog} instance.
  49. *
  50. * @param {Props} props - The React {@code Component} props to initialize
  51. * the new {@code ConnectedSettingsDialog} instance with.
  52. */
  53. constructor(props: Props) {
  54. super(props);
  55. // Bind event handlers so they are only bound once for every instance.
  56. this._closeDialog = this._closeDialog.bind(this);
  57. }
  58. /**
  59. * Implements React's {@link Component#render()}.
  60. *
  61. * @inheritdoc
  62. * @returns {ReactElement}
  63. */
  64. render() {
  65. const { _tabs, defaultTab, dispatch } = this.props;
  66. const onSubmit = this._closeDialog;
  67. const defaultTabIdx
  68. = _tabs.findIndex(({ name }) => name === defaultTab);
  69. const tabs = _tabs.map(tab => {
  70. return {
  71. ...tab,
  72. onMount: tab.onMount
  73. ? (...args) => dispatch(tab.onMount(...args))
  74. : undefined,
  75. submit: (...args) => tab.submit
  76. && dispatch(tab.submit(...args))
  77. };
  78. });
  79. return (
  80. <DialogWithTabs
  81. closeDialog = { this._closeDialog }
  82. cssClassName = 'settings-dialog'
  83. defaultTab = {
  84. defaultTabIdx === -1 ? undefined : defaultTabIdx
  85. }
  86. onSubmit = { onSubmit }
  87. tabs = { tabs }
  88. titleKey = 'settings.title' />
  89. );
  90. }
  91. _closeDialog: () => void;
  92. /**
  93. * Callback invoked to close the dialog without saving changes.
  94. *
  95. * @private
  96. * @returns {void}
  97. */
  98. _closeDialog() {
  99. this.props.dispatch(hideDialog());
  100. }
  101. }
  102. /**
  103. * Maps (parts of) the Redux state to the associated props for the
  104. * {@code ConnectedSettingsDialog} component.
  105. *
  106. * @param {Object} state - The Redux state.
  107. * @private
  108. * @returns {{
  109. * tabs: Array<Object>
  110. * }}
  111. */
  112. function _mapStateToProps(state) {
  113. const configuredTabs = interfaceConfig.SETTINGS_SECTIONS || [];
  114. // The settings sections to display.
  115. const showDeviceSettings = configuredTabs.includes('devices');
  116. const moreTabProps = getMoreTabProps(state);
  117. const { showModeratorSettings, showLanguageSettings, showPrejoinSettings } = moreTabProps;
  118. const showProfileSettings
  119. = configuredTabs.includes('profile') && !state['features/base/config'].disableProfile;
  120. const showCalendarSettings
  121. = configuredTabs.includes('calendar') && isCalendarEnabled(state);
  122. const tabs = [];
  123. if (showDeviceSettings) {
  124. tabs.push({
  125. name: SETTINGS_TABS.DEVICES,
  126. component: DeviceSelection,
  127. label: 'settings.devices',
  128. onMount: getAvailableDevices,
  129. props: getDeviceSelectionDialogProps(state),
  130. propsUpdateFunction: (tabState, newProps) => {
  131. // Ensure the device selection tab gets updated when new devices
  132. // are found by taking the new props and only preserving the
  133. // current user selected devices. If this were not done, the
  134. // tab would keep using a copy of the initial props it received,
  135. // leaving the device list to become stale.
  136. return {
  137. ...newProps,
  138. selectedAudioInputId: tabState.selectedAudioInputId,
  139. selectedAudioOutputId: tabState.selectedAudioOutputId,
  140. selectedVideoInputId: tabState.selectedVideoInputId
  141. };
  142. },
  143. styles: 'settings-pane devices-pane',
  144. submit: submitDeviceSelectionTab
  145. });
  146. }
  147. if (showProfileSettings) {
  148. tabs.push({
  149. name: SETTINGS_TABS.PROFILE,
  150. component: ProfileTab,
  151. label: 'profile.title',
  152. props: getProfileTabProps(state),
  153. styles: 'settings-pane profile-pane',
  154. submit: submitProfileTab
  155. });
  156. }
  157. if (showCalendarSettings) {
  158. tabs.push({
  159. name: SETTINGS_TABS.CALENDAR,
  160. component: CalendarTab,
  161. label: 'settings.calendar.title',
  162. styles: 'settings-pane calendar-pane'
  163. });
  164. }
  165. if (showModeratorSettings || showLanguageSettings || showPrejoinSettings) {
  166. tabs.push({
  167. name: SETTINGS_TABS.MORE,
  168. component: MoreTab,
  169. label: 'settings.more',
  170. props: moreTabProps,
  171. propsUpdateFunction: (tabState, newProps) => {
  172. // Updates tab props, keeping users selection
  173. return {
  174. ...newProps,
  175. currentLanguage: tabState.currentLanguage,
  176. followMeEnabled: tabState.followMeEnabled,
  177. showPrejoinPage: tabState.showPrejoinPage,
  178. startAudioMuted: tabState.startAudioMuted,
  179. startVideoMuted: tabState.startVideoMuted
  180. };
  181. },
  182. styles: 'settings-pane more-pane',
  183. submit: submitMoreTab
  184. });
  185. }
  186. return { _tabs: tabs };
  187. }
  188. export default connect(_mapStateToProps)(SettingsDialog);