|
1 | | -import {useTranslation} from 'react-i18next' |
| 1 | +import { useTranslation } from 'react-i18next' |
2 | 2 | import TextField from '@material-ui/core/TextField' |
3 | 3 | import { |
4 | | - Box, |
5 | | - Button, |
6 | | - CircularProgress, |
7 | | - FormControlLabel, |
8 | | - FormGroup, |
9 | | - FormHelperText, |
10 | | - InputAdornment, |
11 | | - InputLabel, |
12 | | - MenuItem, |
13 | | - Select, |
14 | | - Switch, |
| 4 | + Box, |
| 5 | + Button, |
| 6 | + CircularProgress, |
| 7 | + FormControlLabel, |
| 8 | + FormGroup, |
| 9 | + FormHelperText, |
| 10 | + InputAdornment, |
| 11 | + InputLabel, |
| 12 | + MenuItem, |
| 13 | + Select, |
| 14 | + Switch, |
15 | 15 | } from '@material-ui/core' |
16 | | -import {styled} from '@material-ui/core/styles' |
17 | | -import {useEffect, useMemo, useState} from 'react' |
| 16 | +import { styled } from '@material-ui/core/styles' |
| 17 | +import { useEffect, useMemo, useState } from 'react' |
18 | 18 |
|
19 | | -import {SecondarySettingsContent, SettingSectionLabel} from './style' |
| 19 | +import { SecondarySettingsContent, SettingSectionLabel } from './style' |
20 | 20 |
|
21 | 21 | // Create a styled status message component |
22 | 22 | const StatusMessage = styled('div')(({ theme, severity }) => ({ |
@@ -72,6 +72,15 @@ export default function SecondarySettingsComponent({ settings, inputForm }) { |
72 | 72 | ProxyHosts, |
73 | 73 | } = settings || {} |
74 | 74 |
|
| 75 | + // Local state for ProxyHosts text input |
| 76 | + const [proxyHostsText, setProxyHostsText] = useState('') |
| 77 | + |
| 78 | + // Sync proxyHostsText with ProxyHosts when settings change |
| 79 | + useEffect(() => { |
| 80 | + const textValue = Array.isArray(ProxyHosts) ? ProxyHosts.join(', ') : ProxyHosts || '' |
| 81 | + setProxyHostsText(textValue) |
| 82 | + }, [ProxyHosts]) |
| 83 | + |
75 | 84 | // Use useMemo to compute basePath once |
76 | 85 | const basePath = useMemo(() => { |
77 | 86 | if (typeof window !== 'undefined') { |
@@ -443,39 +452,47 @@ export default function SecondarySettingsComponent({ settings, inputForm }) { |
443 | 452 | </StatusMessage> |
444 | 453 | )} |
445 | 454 | </Box> |
446 | | - {/* ProxyP2P */} |
447 | | - <SettingSectionLabel style={{ marginTop: '20px' }}>{t('Proxy')}</SettingSectionLabel> |
448 | | - <FormGroup> |
449 | | - <FormControlLabel |
450 | | - control={<Switch checked={EnableProxy} onChange={inputForm} id='EnableProxy' color='secondary' />} |
451 | | - label={t('SettingsDialog.EnableProxy')} |
452 | | - labelPlacement='start' |
453 | | - /> |
454 | | - <FormHelperText margin='none'>{t('SettingsDialog.EnableProxyHint')}</FormHelperText> |
455 | | - </FormGroup> |
456 | | - {/* Proxy hosts */} |
457 | | - <TextField |
458 | | - onChange={(e) => { |
459 | | - const hostsArray = e.target.value |
460 | | - .split(',') |
461 | | - .map((s) => s.trim()); |
462 | | - |
463 | | - inputForm({ |
464 | | - target: { |
465 | | - id: 'ProxyHosts', |
466 | | - value: hostsArray, |
467 | | - }, |
468 | | - }); |
469 | | - }} |
470 | | - margin='normal' |
471 | | - id='ProxyHosts' |
472 | | - label={t('SettingsDialog.ProxyHosts')} |
473 | | - helperText={t('SettingsDialog.ProxyHostsHint')} |
474 | | - value={Array.isArray(ProxyHosts) ? ProxyHosts.join(', ') : ''} |
475 | | - type='text' |
476 | | - variant='outlined' |
477 | | - fullWidth |
| 455 | + {/* ProxyP2P */} |
| 456 | + <SettingSectionLabel style={{ marginTop: '20px' }}>{t('Proxy')}</SettingSectionLabel> |
| 457 | + <FormGroup> |
| 458 | + <FormControlLabel |
| 459 | + control={<Switch checked={EnableProxy} onChange={inputForm} id='EnableProxy' color='secondary' />} |
| 460 | + label={t('SettingsDialog.EnableProxy')} |
| 461 | + labelPlacement='start' |
478 | 462 | /> |
| 463 | + <FormHelperText margin='none'>{t('SettingsDialog.EnableProxyHint')}</FormHelperText> |
| 464 | + </FormGroup> |
| 465 | + {/* Proxy hosts */} |
| 466 | + <TextField |
| 467 | + onChange={e => { |
| 468 | + setProxyHostsText(e.target.value) |
| 469 | + }} |
| 470 | + onBlur={e => { |
| 471 | + const inputValue = e.target.value.trim() |
| 472 | + const hostsArray = |
| 473 | + inputValue === '' |
| 474 | + ? [] |
| 475 | + : inputValue |
| 476 | + .split(',') |
| 477 | + .map(s => s.trim()) |
| 478 | + .filter(s => s !== '') |
| 479 | + |
| 480 | + inputForm({ |
| 481 | + target: { |
| 482 | + id: 'ProxyHosts', |
| 483 | + value: hostsArray, |
| 484 | + }, |
| 485 | + }) |
| 486 | + }} |
| 487 | + margin='normal' |
| 488 | + id='ProxyHosts' |
| 489 | + label={t('SettingsDialog.ProxyHosts')} |
| 490 | + helperText={t('SettingsDialog.ProxyHostsHint')} |
| 491 | + value={proxyHostsText} |
| 492 | + type='text' |
| 493 | + variant='outlined' |
| 494 | + fullWidth |
| 495 | + /> |
479 | 496 | </SecondarySettingsContent> |
480 | 497 | ) |
481 | 498 | } |
0 commit comments