您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ConferenceSection.tsx 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import React, { useCallback, useEffect, useMemo, useState } 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.native';
  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 {
  17. serverURL,
  18. startCarMode,
  19. startWithAudioMuted,
  20. startWithVideoMuted
  21. } = useSelector((state: IReduxState) => state['features/base/settings']);
  22. const defaultServerURL = useSelector((state: IReduxState) => getDefaultURL(state));
  23. const [ newServerURL, setNewServerURL ] = useState(serverURL ?? '');
  24. const serverURLChangeEnabled = useSelector((state: IReduxState) => isServerURLChangeEnabled(state));
  25. const switches = useMemo(() => [
  26. {
  27. label: 'settingsView.startCarModeInLowBandwidthMode',
  28. state: startCarMode,
  29. name: 'startCarMode'
  30. },
  31. {
  32. label: 'settingsView.startWithAudioMuted',
  33. state: startWithAudioMuted,
  34. name: 'startWithAudioMuted'
  35. },
  36. {
  37. label: 'settingsView.startWithVideoMuted',
  38. state: startWithVideoMuted,
  39. name: 'startWithVideoMuted'
  40. }
  41. ], [ startCarMode, startWithAudioMuted, startWithVideoMuted ]);
  42. const onChangeServerURL = useCallback(value => {
  43. setNewServerURL(value);
  44. dispatch(updateSettings({
  45. serverURL: value
  46. }));
  47. }, [ dispatch, newServerURL ]);
  48. const processServerURL = useCallback(() => {
  49. const normalizedURL = normalizeUserInputURL(newServerURL);
  50. onChangeServerURL(normalizedURL);
  51. }, [ newServerURL ]);
  52. useEffect(() => () => processServerURL(), []);
  53. const onSwitchToggled = useCallback((name: string) => (enabled?: boolean) => {
  54. // @ts-ignore
  55. dispatch(updateSettings({ [name]: enabled }));
  56. }, [ dispatch ]);
  57. return (
  58. <FormSection
  59. label = 'settingsView.conferenceSection'>
  60. <Input
  61. autoCapitalize = 'none'
  62. customStyles = {{ container: styles.customContainer }}
  63. editable = { serverURLChangeEnabled }
  64. keyboardType = { 'url' }
  65. label = { t('settingsView.serverURL') }
  66. onBlur = { processServerURL }
  67. onChange = { onChangeServerURL }
  68. placeholder = { defaultServerURL }
  69. textContentType = { 'URL' } // iOS only
  70. value = { newServerURL } />
  71. {
  72. switches.map(({ label, state, name }) => (
  73. <FormRow
  74. key = { label }
  75. label = { label }>
  76. <Switch
  77. checked = { Boolean(state) }
  78. onChange = { onSwitchToggled(name) } />
  79. </FormRow>
  80. ))
  81. }
  82. </FormSection>
  83. );
  84. };
  85. export default ConferenceSection;