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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. // @flow
  2. import React, { Component } from 'react';
  3. import { connect } from 'react-redux';
  4. import { getAvailableDevices } from '../../../base/devices';
  5. import { DialogWithTabs, hideDialog } from '../../../base/dialog';
  6. import { isCalendarEnabled } from '../../../calendar-sync';
  7. import {
  8. DeviceSelection,
  9. getDeviceSelectionDialogProps,
  10. submitDeviceSelectionTab
  11. } from '../../../device-selection';
  12. import CalendarTab from './CalendarTab';
  13. import MoreTab from './MoreTab';
  14. import ProfileTab from './ProfileTab';
  15. import { getMoreTabProps, getProfileTabProps } from '../../functions';
  16. import { submitMoreTab, submitProfileTab } from '../../actions';
  17. import { SETTINGS_TABS } from '../../constants';
  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. defaultTab = {
  83. defaultTabIdx === -1 ? undefined : defaultTabIdx
  84. }
  85. onSubmit = { onSubmit }
  86. tabs = { tabs } />
  87. );
  88. }
  89. _closeDialog: () => void;
  90. /**
  91. * Callback invoked to close the dialog without saving changes.
  92. *
  93. * @private
  94. * @returns {void}
  95. */
  96. _closeDialog() {
  97. this.props.dispatch(hideDialog());
  98. }
  99. }
  100. /**
  101. * Maps (parts of) the Redux state to the associated props for the
  102. * {@code ConnectedSettingsDialog} component.
  103. *
  104. * @param {Object} state - The Redux state.
  105. * @private
  106. * @returns {{
  107. * tabs: Array<Object>
  108. * }}
  109. */
  110. function _mapStateToProps(state) {
  111. const configuredTabs = interfaceConfig.SETTINGS_SECTIONS || [];
  112. const jwt = state['features/base/jwt'];
  113. // The settings sections to display.
  114. const showDeviceSettings = configuredTabs.includes('devices');
  115. const moreTabProps = getMoreTabProps(state);
  116. const { showModeratorSettings, showLanguageSettings } = moreTabProps;
  117. const showProfileSettings
  118. = configuredTabs.includes('profile') && jwt.isGuest;
  119. const showCalendarSettings
  120. = configuredTabs.includes('calendar') && isCalendarEnabled();
  121. const tabs = [];
  122. if (showDeviceSettings) {
  123. tabs.push({
  124. name: SETTINGS_TABS.DEVICES,
  125. component: DeviceSelection,
  126. label: 'settings.devices',
  127. onMount: getAvailableDevices,
  128. props: getDeviceSelectionDialogProps(state),
  129. propsUpdateFunction: (tabState, newProps) => {
  130. // Ensure the device selection tab gets updated when new devices
  131. // are found by taking the new props and only preserving the
  132. // current user selected devices. If this were not done, the
  133. // tab would keep using a copy of the initial props it received,
  134. // leaving the device list to become stale.
  135. return {
  136. ...newProps,
  137. selectedAudioInputId: tabState.selectedAudioInputId,
  138. selectedAudioOutputId: tabState.selectedAudioOutputId,
  139. selectedVideoInputId: tabState.selectedVideoInputId
  140. };
  141. },
  142. styles: 'settings-pane devices-pane',
  143. submit: submitDeviceSelectionTab
  144. });
  145. }
  146. if (showProfileSettings) {
  147. tabs.push({
  148. name: SETTINGS_TABS.PROFILE,
  149. component: ProfileTab,
  150. label: 'profile.title',
  151. props: getProfileTabProps(state),
  152. styles: 'settings-pane profile-pane',
  153. submit: submitProfileTab
  154. });
  155. }
  156. if (showCalendarSettings) {
  157. tabs.push({
  158. name: SETTINGS_TABS.CALENDAR,
  159. component: CalendarTab,
  160. label: 'settings.calendar.title',
  161. styles: 'settings-pane calendar-pane'
  162. });
  163. }
  164. if (showModeratorSettings || showLanguageSettings) {
  165. tabs.push({
  166. name: SETTINGS_TABS.MORE,
  167. component: MoreTab,
  168. label: 'settings.more',
  169. props: moreTabProps,
  170. styles: 'settings-pane more-pane',
  171. submit: submitMoreTab
  172. });
  173. }
  174. return { _tabs: tabs };
  175. }
  176. export default connect(_mapStateToProps)(SettingsDialog);