Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

SettingsDialog.tsx 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  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, IconModerator, 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. '& .moderator-settings-wrapper': {
  133. paddingTop: '20px'
  134. },
  135. '& .calendar-tab': {
  136. alignItems: 'center',
  137. flexDirection: 'column',
  138. fontSize: '14px',
  139. minHeight: '100px',
  140. textAlign: 'center'
  141. },
  142. '& .calendar-tab-sign-in': {
  143. marginTop: '20px'
  144. },
  145. '& .sign-out-cta': {
  146. marginBottom: '20px'
  147. },
  148. '& .sign-out-cta-button': {
  149. display: 'flex',
  150. justifyContent: 'center'
  151. },
  152. '@media only screen and (max-width: 700px)': {
  153. '& .device-selection': {
  154. display: 'flex',
  155. flexDirection: 'column'
  156. },
  157. '& .more-tab': {
  158. flexDirection: 'column'
  159. }
  160. }
  161. }
  162. };
  163. };
  164. /**
  165. * A React {@code Component} for displaying a dialog to modify local settings
  166. * and conference-wide (moderator) settings. This version is connected to
  167. * redux to get the current settings.
  168. *
  169. * @augments Component
  170. */
  171. class SettingsDialog extends Component<IProps> {
  172. /**
  173. * Implements React's {@link Component#render()}.
  174. *
  175. * @inheritdoc
  176. * @returns {ReactElement}
  177. */
  178. render() {
  179. const { _tabs, defaultTab, dispatch } = this.props;
  180. const correctDefaultTab = _tabs.find(tab => tab.name === defaultTab)?.name;
  181. const tabs = _tabs.map(tab => {
  182. return {
  183. ...tab,
  184. submit: (...args: any) => tab.submit
  185. && dispatch(tab.submit(...args))
  186. };
  187. });
  188. return (
  189. <DialogWithTabs
  190. className = 'settings-dialog'
  191. defaultTab = { correctDefaultTab }
  192. tabs = { tabs }
  193. titleKey = 'settings.title' />
  194. );
  195. }
  196. }
  197. /**
  198. * Maps (parts of) the Redux state to the associated props for the
  199. * {@code ConnectedSettingsDialog} component.
  200. *
  201. * @param {Object} state - The Redux state.
  202. * @param {Object} ownProps - The props passed to the component.
  203. * @private
  204. * @returns {{
  205. * tabs: Array<Object>
  206. * }}
  207. */
  208. function _mapStateToProps(state: IReduxState, ownProps: any) {
  209. const { classes, isDisplayedOnWelcomePage } = ownProps;
  210. const configuredTabs = interfaceConfig.SETTINGS_SECTIONS || [];
  211. // The settings sections to display.
  212. const showDeviceSettings = configuredTabs.includes('devices');
  213. const moreTabProps = getMoreTabProps(state);
  214. const moderatorTabProps = getModeratorTabProps(state);
  215. const { showModeratorSettings } = moderatorTabProps;
  216. const showMoreTab = configuredTabs.includes('more');
  217. const showProfileSettings
  218. = configuredTabs.includes('profile') && !state['features/base/config'].disableProfile;
  219. const showCalendarSettings
  220. = configuredTabs.includes('calendar') && isCalendarEnabled(state);
  221. const showSoundsSettings = configuredTabs.includes('sounds');
  222. const tabs: IDialogTab[] = [];
  223. if (showDeviceSettings) {
  224. tabs.push({
  225. name: SETTINGS_TABS.DEVICES,
  226. component: DeviceSelection,
  227. labelKey: 'settings.devices',
  228. props: getDeviceSelectionDialogProps(state, isDisplayedOnWelcomePage),
  229. propsUpdateFunction: (tabState: any, newProps: any) => {
  230. // Ensure the device selection tab gets updated when new devices
  231. // are found by taking the new props and only preserving the
  232. // current user selected devices. If this were not done, the
  233. // tab would keep using a copy of the initial props it received,
  234. // leaving the device list to become stale.
  235. return {
  236. ...newProps,
  237. selectedAudioInputId: tabState.selectedAudioInputId,
  238. selectedAudioOutputId: tabState.selectedAudioOutputId,
  239. selectedVideoInputId: tabState.selectedVideoInputId
  240. };
  241. },
  242. className: `settings-pane ${classes.settingsDialog} devices-pane`,
  243. submit: (newState: any) => submitDeviceSelectionTab(newState, isDisplayedOnWelcomePage),
  244. icon: IconVolumeUp
  245. });
  246. }
  247. if (showProfileSettings) {
  248. tabs.push({
  249. name: SETTINGS_TABS.PROFILE,
  250. component: ProfileTab,
  251. labelKey: 'profile.title',
  252. props: getProfileTabProps(state),
  253. className: `settings-pane ${classes.settingsDialog}`,
  254. submit: submitProfileTab,
  255. icon: IconUser
  256. });
  257. }
  258. if (showModeratorSettings) {
  259. tabs.push({
  260. name: SETTINGS_TABS.MODERATOR,
  261. component: ModeratorTab,
  262. labelKey: 'settings.moderator',
  263. props: moderatorTabProps,
  264. propsUpdateFunction: (tabState: any, newProps: any) => {
  265. // Updates tab props, keeping users selection
  266. return {
  267. ...newProps,
  268. followMeEnabled: tabState?.followMeEnabled,
  269. startAudioMuted: tabState?.startAudioMuted,
  270. startVideoMuted: tabState?.startVideoMuted,
  271. startReactionsMuted: tabState?.startReactionsMuted
  272. };
  273. },
  274. className: `settings-pane ${classes.settingsDialog} moderator-pane`,
  275. submit: submitModeratorTab,
  276. icon: IconModerator
  277. });
  278. }
  279. if (showCalendarSettings) {
  280. tabs.push({
  281. name: SETTINGS_TABS.CALENDAR,
  282. component: CalendarTab,
  283. labelKey: 'settings.calendar.title',
  284. className: `settings-pane ${classes.settingsDialog} calendar-pane`,
  285. icon: IconCalendar
  286. });
  287. }
  288. if (showSoundsSettings) {
  289. tabs.push({
  290. name: SETTINGS_TABS.SOUNDS,
  291. component: SoundsTab,
  292. labelKey: 'settings.sounds',
  293. props: getSoundsTabProps(state),
  294. className: `settings-pane ${classes.settingsDialog} profile-pane`,
  295. submit: submitSoundsTab,
  296. icon: IconBell
  297. });
  298. }
  299. if (showMoreTab) {
  300. tabs.push({
  301. name: SETTINGS_TABS.MORE,
  302. // @ts-ignore
  303. component: MoreTab,
  304. labelKey: 'settings.more',
  305. props: moreTabProps,
  306. propsUpdateFunction: (tabState: any, newProps: any) => {
  307. // Updates tab props, keeping users selection
  308. return {
  309. ...newProps,
  310. currentFramerate: tabState?.currentFramerate,
  311. currentLanguage: tabState?.currentLanguage,
  312. hideSelfView: tabState?.hideSelfView,
  313. showPrejoinPage: tabState?.showPrejoinPage,
  314. enabledNotifications: tabState?.enabledNotifications || {},
  315. maxStageParticipants: tabState?.maxStageParticipants
  316. };
  317. },
  318. className: `settings-pane ${classes.settingsDialog} more-pane`,
  319. submit: submitMoreTab,
  320. icon: IconGear
  321. });
  322. }
  323. return { _tabs: tabs };
  324. }
  325. export default withStyles(styles)(connect(_mapStateToProps)(SettingsDialog));