diff --git a/web/src/components/Settings/SettingsDialog.jsx b/web/src/components/Settings/SettingsDialog.jsx index c235341..5ed27c9 100644 --- a/web/src/components/Settings/SettingsDialog.jsx +++ b/web/src/components/Settings/SettingsDialog.jsx @@ -1,13 +1,9 @@ import axios from 'axios' import Dialog from '@material-ui/core/Dialog' -import DialogTitle from '@material-ui/core/DialogTitle' -import DialogContent from '@material-ui/core/DialogContent' import TextField from '@material-ui/core/TextField' -import DialogActions from '@material-ui/core/DialogActions' import Button from '@material-ui/core/Button' import Checkbox from '@material-ui/core/Checkbox' import { - ButtonGroup, FormControlLabel, Grid, Input, @@ -27,6 +23,7 @@ import Tabs from '@material-ui/core/Tabs' import Tab from '@material-ui/core/Tab' import SwipeableViews from 'react-swipeable-views' import { USBIcon, RAMIcon } from 'icons' +import CircularProgress from '@material-ui/core/CircularProgress' import { FooterSection, @@ -36,70 +33,31 @@ import { SecondarySettingsContent, StorageButton, StorageIconWrapper, - CacheSizeSettings, CacheStorageSelector, - CacheStorageSettings, - SettingSection, - SettingLabel, SettingSectionLabel, PreloadCachePercentage, cacheBeforeReaderColor, cacheAfterReaderColor, + Content, } from './style' - -const a11yProps = index => ({ - id: `full-width-tab-${index}`, - 'aria-controls': `full-width-tabpanel-${index}`, -}) - -const TabPanel = ({ children, value, index, ...other }) => ( - -) - -const defaultSettings = { - CacheSize: 96, - ReaderReadAHead: 95, - UseDisk: false, - UploadRateLimit: 0, - TorrentsSavePath: '', - ConnectionsLimit: 23, - DhtConnectionLimit: 500, - DisableDHT: false, - DisablePEX: false, - DisableTCP: false, - DisableUPNP: false, - DisableUTP: true, - DisableUpload: false, - DownloadRateLimit: 0, - EnableDebug: false, - EnableIPv6: false, - ForceEncrypt: false, - PeersListenPort: 0, - PreloadBuffer: false, - RemoveCacheOnDrop: false, - RetrackersMode: 1, - Strategy: 0, - TorrentDisconnectTimeout: 30, -} +import defaultSettings from './defaultSettings' +import { a11yProps, TabPanel } from './tabComponents' export default function SettingsDialog({ handleClose }) { const { t } = useTranslation() - const fullScreen = useMediaQuery('@media (max-width:930px)') + const { direction } = useTheme() const [settings, setSettings] = useState() - const [show, setShow] = useState(false) + const [selectedTab, setSelectedTab] = useState(0) + const [cacheSize, setCacheSize] = useState(32) + const [cachePercentage, setCachePercentage] = useState(40) + const [isProMode, setIsProMode] = useState(JSON.parse(localStorage.getItem('isProMode')) || false) useEffect(() => { - axios - .post(settingsHost(), { action: 'get' }) - .then(({ data }) => { - setSettings({ ...data, CacheSize: data.CacheSize / (1024 * 1024) }) - setShow(true) - }) - .catch(() => setShow(false)) + axios.post(settingsHost(), { action: 'get' }).then(({ data }) => { + setSettings({ ...data, CacheSize: data.CacheSize / (1024 * 1024) }) + }) }, []) const handleSave = () => { @@ -155,19 +113,6 @@ export default function SettingsDialog({ handleClose }) { RemoveCacheOnDrop, } = settings || {} - const updateSettings = newProps => setSettings({ ...settings, ...newProps }) - - const { direction } = useTheme() - const [selectedTab, setSelectedTab] = useState(0) - - const handleChange = (_, newValue) => setSelectedTab(newValue) - - const handleChangeIndex = index => setSelectedTab(index) - - const [cacheSize, setCacheSize] = useState(32) - const [cachePercentage, setCachePercentage] = useState(40) - const [isProMode, setIsProMode] = useState(JSON.parse(localStorage.getItem('isProMode')) || false) - useEffect(() => { if (!CacheSize || !ReaderReadAHead) return @@ -175,331 +120,339 @@ export default function SettingsDialog({ handleClose }) { setCachePercentage(ReaderReadAHead) }, [CacheSize, ReaderReadAHead]) + const updateSettings = newProps => setSettings({ ...settings, ...newProps }) + const handleChange = (_, newValue) => setSelectedTab(newValue) + const handleChangeIndex = index => setSelectedTab(index) const handleBlur = ({ target: { value } }) => { if (value < 32) return setCacheSize(32) if (value > 20000) return setCacheSize(20000) setCacheSize(Math.round(value / 8) * 8) } - - const handleInputChange = ({ target: { value } }) => { - setCacheSize(value === '' ? '' : Number(value)) - } + const handleInputChange = ({ target: { value } }) => setCacheSize(value === '' ? '' : Number(value)) return (
{t('Settings')}
- {settings ? ( - <> - - + {settings ? ( + <> + + + + + + + + + - + + +
+ Настройки кеша - - - + - - - - - Настройки кеша + +
+ {100 - cachePercentage}% ({Math.round((cacheSize / 100) * (100 - cachePercentage))} МБ) +
- +
От кеша будет оставаться позади воспроизводимого блока
+
- -
- {100 - cachePercentage}% ({Math.round((cacheSize / 100) * (100 - cachePercentage))} МБ) -
-
От кеша будет оставаться позади воспроизводимого блока
-
+ +
+ {cachePercentage}% ({Math.round((cacheSize / 100) * cachePercentage)} МБ) +
- -
- {cachePercentage}% ({Math.round((cacheSize / 100) * cachePercentage)} МБ) -
-
От кеша будет спереди от воспроизводимого блока
-
+
От кеша будет спереди от воспроизводимого блока
+
- + - - Размер кеша +
+
Размер кеша
- - - setCacheSize(newValue)} - step={8} - /> - - - {isProMode && ( - - + + setCacheSize(newValue)} + step={8} /> - )} - - - - Кеш предзагрузки - - - - setCachePercentage(newValue)} - /> + {isProMode && ( + + + + )} +
- {isProMode && ( - - +
Кеш предзагрузки
+ + + + setCachePercentage(value === '' ? '' : Number(value))} - onBlur={({ target: { value } }) => { - if (value < 0) return setCachePercentage(0) - if (value > 100) return setCachePercentage(100) - }} - style={{ width: '65px' }} - inputProps={{ min: 0, max: 100, type: 'number' }} + onChange={(_, newValue) => setCachePercentage(newValue)} /> - )} - -
- - } - label={t('PreloadBuffer')} - /> -
+ {isProMode && ( + + + setCachePercentage(value === '' ? '' : Number(value)) + } + onBlur={({ target: { value } }) => { + if (value < 0) return setCachePercentage(0) + if (value > 100) return setCachePercentage(100) + }} + style={{ width: '65px' }} + inputProps={{ min: 0, max: 100, type: 'number' }} + /> + + )} + + - {UseDisk ? ( - - Место хранения кеша + + } + label={t('PreloadBuffer')} + /> +
-
- updateSettings({ UseDisk: false })}> - - + {UseDisk ? ( +
+ Место хранения кеша + +
+ updateSettings({ UseDisk: false })}> + + + + +
Оперативная память
+
+ + + + + + +
Диск
+
+
+ + + } + label={t('RemoveCacheOnDrop')} + /> + {t('RemoveCacheOnDropDesc')} + + +
+ ) : ( + + + Место хранения кеша + + + + +
Оперативная память
- - - + updateSettings({ UseDisk: true })}> + +
Диск
-
+ + )} +
+
- - } - label={t('RemoveCacheOnDrop')} - /> - {t('RemoveCacheOnDropDesc')} + + + Дополнительные настройки - - - ) : ( - - - Место хранения кеша - - - - - - - -
Оперативная память
-
- - updateSettings({ UseDisk: true })}> - - - - -
Диск
-
-
- )} - -
- - - - Дополнительные настройки - - } - label={t('EnableIPv6')} - /> -
- } - label={t('TCP')} - /> -
- } - label={t('UTP')} - /> -
- } - label={t('PEX')} - /> -
- } - label={t('ForceEncrypt')} - /> -
- -
- -
- } - label={t('DHT')} - /> -
- -
- -
- } - label={t('Upload')} - /> -
- -
- -
- } - label={t('UPNP')} - /> -
- {t('RetrackersMode')} - -
-
-
-
- - ) : ( - 'loading...' - )} + } + label={t('EnableIPv6')} + /> +
+ } + label={t('TCP')} + /> +
+ } + label={t('UTP')} + /> +
+ } + label={t('PEX')} + /> +
+ } + label={t('ForceEncrypt')} + /> +
+ +
+ +
+ } + label={t('DHT')} + /> +
+ +
+ +
+ + } + label={t('Upload')} + /> +
+ +
+ +
+ } + label={t('UPNP')} + /> +
+ {t('RetrackersMode')} + +
+ + + + + ) : ( + + )} + {/* {t('Settings')} css` + background: #f1eff3; + min-height: 500px; + + ${isLoading && + css` + display: grid; + place-items: center; + `} + `} +` + export const PreloadCacheValue = styled.div` ${({ color }) => css` display: grid; @@ -43,7 +56,6 @@ export const PreloadCacheValue = styled.div` ` export const MainSettingsContent = styled.div` - min-height: 500px; display: grid; grid-template-columns: repeat(2, 1fr); gap: 40px; @@ -54,7 +66,6 @@ export const MainSettingsContent = styled.div` } ` export const SecondarySettingsContent = styled.div` - min-height: 500px; padding: 20px; ` @@ -101,7 +112,6 @@ export const StorageIconWrapper = styled.div` `} ` -export const CacheSizeSettings = styled.div`` export const CacheStorageSelector = styled.div` display: grid; grid-template-rows: max-content 1fr; @@ -115,10 +125,6 @@ export const CacheStorageSelector = styled.div` } ` -export const CacheStorageSettings = styled.div`` - -export const SettingSection = styled.section`` -export const SettingLabel = styled.div`` export const SettingSectionLabel = styled.div` font-size: 25px; padding-bottom: 20px; diff --git a/web/src/components/Settings/tabComponents.jsx b/web/src/components/Settings/tabComponents.jsx new file mode 100644 index 0000000..7bdff3c --- /dev/null +++ b/web/src/components/Settings/tabComponents.jsx @@ -0,0 +1,10 @@ +export const a11yProps = index => ({ + id: `full-width-tab-${index}`, + 'aria-controls': `full-width-tabpanel-${index}`, +}) + +export const TabPanel = ({ children, value, index, ...other }) => ( + +)