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

SettingsDialog.js 11KB

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