Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

SettingsDialog.tsx 11KB

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