Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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