You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ConferenceSection.tsx 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import React, { useCallback, useEffect, useMemo } from 'react';
  2. import { useTranslation } from 'react-i18next';
  3. import { useDispatch, useSelector } from 'react-redux';
  4. import { getDefaultURL } from '../../../app/functions.native';
  5. import { IReduxState } from '../../../app/types';
  6. import { updateSettings } from '../../../base/settings/actions';
  7. import Input from '../../../base/ui/components/native/Input';
  8. import Switch from '../../../base/ui/components/native/Switch';
  9. import { isServerURLChangeEnabled, normalizeUserInputURL } from '../../functions.any';
  10. import FormRow from './FormRow';
  11. import FormSection from './FormSection';
  12. import styles from './styles';
  13. const ConferenceSection = () => {
  14. const { t } = useTranslation();
  15. const dispatch = useDispatch();
  16. const defaultServerURL = useSelector((state: IReduxState) => getDefaultURL(state));
  17. const {
  18. serverURL,
  19. startCarMode,
  20. startWithAudioMuted,
  21. startWithVideoMuted
  22. } = useSelector((state: IReduxState) => state['features/base/settings']);
  23. const { serverURLChangeEnabled } = useSelector((state: IReduxState) => isServerURLChangeEnabled(state));
  24. const switches = useMemo(() => [
  25. {
  26. label: 'settingsView.startCarModeInLowBandwidthMode',
  27. state: startCarMode,
  28. name: 'startCarMode'
  29. },
  30. {
  31. label: 'settingsView.startWithAudioMuted',
  32. state: startWithAudioMuted,
  33. name: 'startWithAudioMuted'
  34. },
  35. {
  36. label: 'settingsView.startWithVideoMuted',
  37. state: startWithVideoMuted,
  38. name: 'startWithVideoMuted'
  39. }
  40. ], [ startCarMode, startWithAudioMuted, startWithVideoMuted ]);
  41. const onChangeServerURL = useCallback(newServerURL => {
  42. dispatch(updateSettings({ serverURL: newServerURL }));
  43. }, [ updateSettings ]);
  44. const processServerURL = useCallback(() => {
  45. const normalizedURL = normalizeUserInputURL(serverURL ?? '');
  46. onChangeServerURL(normalizedURL);
  47. }, [ serverURL ]);
  48. useEffect(() => () => processServerURL(), []);
  49. const onSwitchToggled = useCallback((name: string) => (enabled?: boolean) => {
  50. dispatch(updateSettings({ [name]: enabled }));
  51. }, [ dispatch, updateSettings ]);
  52. return (
  53. <FormSection
  54. label = 'settingsView.conferenceSection'>
  55. <Input
  56. autoCapitalize = 'none'
  57. customStyles = {{ container: styles.customContainer }}
  58. editable = { serverURLChangeEnabled }
  59. keyboardType = { 'url' }
  60. label = { t('settingsView.serverURL') }
  61. onBlur = { processServerURL }
  62. onChange = { onChangeServerURL }
  63. placeholder = { defaultServerURL }
  64. textContentType = { 'URL' } // iOS only
  65. value = { serverURL ?? '' } />
  66. {
  67. switches.map(({ label, state, name }) => (
  68. <FormRow
  69. key = { label }
  70. label = { label }>
  71. <Switch
  72. checked = { Boolean(state) }
  73. onChange = { onSwitchToggled(name) } />
  74. </FormRow>
  75. ))
  76. }
  77. </FormSection>
  78. );
  79. };
  80. export default ConferenceSection;