您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

SettingsDialog.tsx 12KB

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