Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

SettingsDialog.tsx 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. import { Theme } from '@mui/material';
  2. import { withStyles } from '@mui/styles';
  3. import React, { Component } from 'react';
  4. import { IReduxState } from '../../../app/types';
  5. import {
  6. IconBell,
  7. IconCalendar,
  8. IconGear,
  9. IconHost,
  10. IconShortcuts,
  11. IconUser,
  12. IconVideo,
  13. IconVolumeUp
  14. } from '../../../base/icons/svg';
  15. import { connect } from '../../../base/redux/functions';
  16. import { withPixelLineHeight } from '../../../base/styles/functions.web';
  17. import DialogWithTabs, { IDialogTab } from '../../../base/ui/components/web/DialogWithTabs';
  18. import { isCalendarEnabled } from '../../../calendar-sync/functions.web';
  19. import { submitAudioDeviceSelectionTab, submitVideoDeviceSelectionTab } from '../../../device-selection/actions.web';
  20. import AudioDevicesSelection from '../../../device-selection/components/AudioDevicesSelection';
  21. import VideoDeviceSelection from '../../../device-selection/components/VideoDeviceSelection';
  22. import {
  23. getAudioDeviceSelectionDialogProps,
  24. getVideoDeviceSelectionDialogProps
  25. } from '../../../device-selection/functions.web';
  26. import {
  27. submitModeratorTab,
  28. submitMoreTab,
  29. submitNotificationsTab,
  30. submitProfileTab,
  31. submitShortcutsTab
  32. } from '../../actions';
  33. import { SETTINGS_TABS } from '../../constants';
  34. import {
  35. getModeratorTabProps,
  36. getMoreTabProps,
  37. getNotificationsMap,
  38. getNotificationsTabProps,
  39. getProfileTabProps,
  40. getShortcutsTabProps
  41. } from '../../functions';
  42. // @ts-ignore
  43. import CalendarTab from './CalendarTab';
  44. import ModeratorTab from './ModeratorTab';
  45. import MoreTab from './MoreTab';
  46. import NotificationsTab from './NotificationsTab';
  47. import ProfileTab from './ProfileTab';
  48. import ShortcutsTab from './ShortcutsTab';
  49. /**
  50. * The type of the React {@code Component} props of
  51. * {@link ConnectedSettingsDialog}.
  52. */
  53. interface IProps {
  54. /**
  55. * Information about the tabs to be rendered.
  56. */
  57. _tabs: IDialogTab<any>[];
  58. /**
  59. * An object containing the CSS classes.
  60. */
  61. classes: Object;
  62. /**
  63. * Which settings tab should be initially displayed. If not defined then
  64. * the first tab will be displayed.
  65. */
  66. defaultTab: string;
  67. /**
  68. * Invoked to save changed settings.
  69. */
  70. dispatch: Function;
  71. /**
  72. * Indicates whether the device selection dialog is displayed on the
  73. * welcome page or not.
  74. */
  75. isDisplayedOnWelcomePage: boolean;
  76. }
  77. /**
  78. * Creates the styles for the component.
  79. *
  80. * @param {Object} theme - The current UI theme.
  81. *
  82. * @returns {Object}
  83. */
  84. const styles = (theme: Theme) => {
  85. return {
  86. settingsDialog: {
  87. display: 'flex',
  88. width: '100%',
  89. '& .auth-name': {
  90. marginBottom: theme.spacing(1)
  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. '& .settings-sub-pane': {
  122. flex: 1
  123. },
  124. '& .settings-sub-pane .right': {
  125. flex: 1
  126. },
  127. '& .settings-sub-pane .left': {
  128. flex: 1
  129. },
  130. '& .settings-sub-pane-element': {
  131. textAlign: 'left',
  132. flex: 1
  133. },
  134. '& .dropdown-menu': {
  135. marginTop: '20px'
  136. },
  137. '& .settings-checkbox': {
  138. display: 'flex',
  139. marginBottom: theme.spacing(3)
  140. },
  141. '& .calendar-tab': {
  142. alignItems: 'center',
  143. flexDirection: 'column',
  144. fontSize: '14px',
  145. minHeight: '100px',
  146. textAlign: 'center',
  147. marginTop: '20px'
  148. },
  149. '& .calendar-tab-sign-in': {
  150. marginTop: '20px'
  151. },
  152. '& .sign-out-cta': {
  153. marginBottom: '20px'
  154. },
  155. '& .sign-out-cta-button': {
  156. display: 'flex',
  157. justifyContent: 'center'
  158. },
  159. '@media only screen and (max-width: 700px)': {
  160. '& .more-tab': {
  161. flexDirection: 'column'
  162. }
  163. }
  164. }
  165. };
  166. };
  167. /**
  168. * A React {@code Component} for displaying a dialog to modify local settings
  169. * and conference-wide (moderator) settings. This version is connected to
  170. * redux to get the current settings.
  171. *
  172. * @augments Component
  173. */
  174. class SettingsDialog extends Component<IProps> {
  175. /**
  176. * Implements React's {@link Component#render()}.
  177. *
  178. * @inheritdoc
  179. * @returns {ReactElement}
  180. */
  181. render() {
  182. const { _tabs, defaultTab, dispatch } = this.props;
  183. const correctDefaultTab = _tabs.find(tab => tab.name === defaultTab)?.name;
  184. const tabs = _tabs.map(tab => {
  185. return {
  186. ...tab,
  187. submit: (...args: any) => tab.submit
  188. && dispatch(tab.submit(...args))
  189. };
  190. });
  191. return (
  192. <DialogWithTabs
  193. className = 'settings-dialog'
  194. defaultTab = { correctDefaultTab }
  195. tabs = { tabs }
  196. titleKey = 'settings.title' />
  197. );
  198. }
  199. }
  200. /**
  201. * Maps (parts of) the Redux state to the associated props for the
  202. * {@code ConnectedSettingsDialog} component.
  203. *
  204. * @param {Object} state - The Redux state.
  205. * @param {Object} ownProps - The props passed to the component.
  206. * @private
  207. * @returns {{
  208. * tabs: Array<Object>
  209. * }}
  210. */
  211. function _mapStateToProps(state: IReduxState, ownProps: any) {
  212. const { classes, isDisplayedOnWelcomePage } = ownProps;
  213. const configuredTabs = interfaceConfig.SETTINGS_SECTIONS || [];
  214. // The settings sections to display.
  215. const showDeviceSettings = configuredTabs.includes('devices');
  216. const moreTabProps = getMoreTabProps(state);
  217. const moderatorTabProps = getModeratorTabProps(state);
  218. const { showModeratorSettings } = moderatorTabProps;
  219. const showMoreTab = configuredTabs.includes('more');
  220. const showProfileSettings
  221. = configuredTabs.includes('profile') && !state['features/base/config'].disableProfile;
  222. const showCalendarSettings
  223. = configuredTabs.includes('calendar') && isCalendarEnabled(state);
  224. const showSoundsSettings = configuredTabs.includes('sounds');
  225. const enabledNotifications = getNotificationsMap(state);
  226. const showNotificationsSettings = Object.keys(enabledNotifications).length > 0;
  227. const tabs: IDialogTab<any>[] = [];
  228. if (showDeviceSettings) {
  229. tabs.push({
  230. name: SETTINGS_TABS.AUDIO,
  231. component: AudioDevicesSelection,
  232. labelKey: 'settings.audio',
  233. props: getAudioDeviceSelectionDialogProps(state, isDisplayedOnWelcomePage),
  234. propsUpdateFunction: (tabState: any, newProps: ReturnType<typeof getAudioDeviceSelectionDialogProps>) => {
  235. // Ensure the device selection tab gets updated when new devices
  236. // are found by taking the new props and only preserving the
  237. // current user selected devices. If this were not done, the
  238. // tab would keep using a copy of the initial props it received,
  239. // leaving the device list to become stale.
  240. return {
  241. ...newProps,
  242. noiseSuppressionEnabled: tabState.noiseSuppressionEnabled,
  243. selectedAudioInputId: tabState.selectedAudioInputId,
  244. selectedAudioOutputId: tabState.selectedAudioOutputId
  245. };
  246. },
  247. className: `settings-pane ${classes.settingsDialog} devices-pane`,
  248. submit: (newState: any) => submitAudioDeviceSelectionTab(newState, isDisplayedOnWelcomePage),
  249. icon: IconVolumeUp
  250. });
  251. tabs.push({
  252. name: SETTINGS_TABS.VIDEO,
  253. component: VideoDeviceSelection,
  254. labelKey: 'settings.video',
  255. props: getVideoDeviceSelectionDialogProps(state, isDisplayedOnWelcomePage),
  256. propsUpdateFunction: (tabState: any, newProps: ReturnType<typeof getVideoDeviceSelectionDialogProps>) => {
  257. // Ensure the device selection tab gets updated when new devices
  258. // are found by taking the new props and only preserving the
  259. // current user selected devices. If this were not done, the
  260. // tab would keep using a copy of the initial props it received,
  261. // leaving the device list to become stale.
  262. return {
  263. ...newProps,
  264. currentFramerate: tabState?.currentFramerate,
  265. localFlipX: tabState.localFlipX,
  266. selectedVideoInputId: tabState.selectedVideoInputId
  267. };
  268. },
  269. className: `settings-pane ${classes.settingsDialog} devices-pane`,
  270. submit: (newState: any) => submitVideoDeviceSelectionTab(newState, isDisplayedOnWelcomePage),
  271. icon: IconVideo
  272. });
  273. }
  274. if (showSoundsSettings || showNotificationsSettings) {
  275. tabs.push({
  276. name: SETTINGS_TABS.NOTIFICATIONS,
  277. component: NotificationsTab,
  278. labelKey: 'settings.notifications',
  279. propsUpdateFunction: (tabState: any, newProps: any) => {
  280. return {
  281. ...newProps,
  282. enabledNotifications: tabState?.enabledNotifications || {}
  283. };
  284. },
  285. props: getNotificationsTabProps(state, showSoundsSettings),
  286. className: `settings-pane ${classes.settingsDialog}`,
  287. submit: submitNotificationsTab,
  288. icon: IconBell
  289. });
  290. }
  291. if (showModeratorSettings) {
  292. tabs.push({
  293. name: SETTINGS_TABS.MODERATOR,
  294. component: ModeratorTab,
  295. labelKey: 'settings.moderator',
  296. props: moderatorTabProps,
  297. propsUpdateFunction: (tabState: any, newProps: typeof moderatorTabProps) => {
  298. // Updates tab props, keeping users selection
  299. return {
  300. ...newProps,
  301. followMeEnabled: tabState?.followMeEnabled,
  302. startAudioMuted: tabState?.startAudioMuted,
  303. startVideoMuted: tabState?.startVideoMuted,
  304. startReactionsMuted: tabState?.startReactionsMuted
  305. };
  306. },
  307. className: `settings-pane ${classes.settingsDialog} moderator-pane`,
  308. submit: submitModeratorTab,
  309. icon: IconHost
  310. });
  311. }
  312. if (showProfileSettings) {
  313. tabs.push({
  314. name: SETTINGS_TABS.PROFILE,
  315. component: ProfileTab,
  316. labelKey: 'profile.title',
  317. props: getProfileTabProps(state),
  318. className: `settings-pane ${classes.settingsDialog} profile-pane`,
  319. submit: submitProfileTab,
  320. icon: IconUser
  321. });
  322. }
  323. if (showCalendarSettings) {
  324. tabs.push({
  325. name: SETTINGS_TABS.CALENDAR,
  326. component: CalendarTab,
  327. labelKey: 'settings.calendar.title',
  328. className: `settings-pane ${classes.settingsDialog} calendar-pane`,
  329. icon: IconCalendar
  330. });
  331. }
  332. tabs.push({
  333. name: SETTINGS_TABS.SHORTCUTS,
  334. component: ShortcutsTab,
  335. labelKey: 'settings.shortcuts',
  336. props: getShortcutsTabProps(state, isDisplayedOnWelcomePage),
  337. propsUpdateFunction: (tabState: any, newProps: any) => {
  338. // Updates tab props, keeping users selection
  339. return {
  340. ...newProps,
  341. keyboardShortcutsEnabled: tabState?.keyboardShortcutsEnabled
  342. };
  343. },
  344. className: `settings-pane ${classes.settingsDialog}`,
  345. submit: submitShortcutsTab,
  346. icon: IconShortcuts
  347. });
  348. if (showMoreTab) {
  349. tabs.push({
  350. name: SETTINGS_TABS.MORE,
  351. // @ts-ignore
  352. component: MoreTab,
  353. labelKey: 'settings.more',
  354. props: moreTabProps,
  355. propsUpdateFunction: (tabState: any, newProps: typeof moreTabProps) => {
  356. // Updates tab props, keeping users selection
  357. return {
  358. ...newProps,
  359. currentLanguage: tabState?.currentLanguage,
  360. hideSelfView: tabState?.hideSelfView,
  361. showPrejoinPage: tabState?.showPrejoinPage,
  362. maxStageParticipants: tabState?.maxStageParticipants
  363. };
  364. },
  365. className: `settings-pane ${classes.settingsDialog} more-pane`,
  366. submit: submitMoreTab,
  367. icon: IconGear
  368. });
  369. }
  370. return { _tabs: tabs };
  371. }
  372. export default withStyles(styles)(connect(_mapStateToProps)(SettingsDialog));