From 3ac2aec6e3d6639936400f309aba55b547957c9f Mon Sep 17 00:00:00 2001 From: Daniel Shleifman Date: Fri, 2 Jul 2021 20:34:29 +0300 Subject: [PATCH] refactor --- .../components/Settings/SettingsDialog.jsx | 137 +++++++++--------- 1 file changed, 70 insertions(+), 67 deletions(-) diff --git a/web/src/components/Settings/SettingsDialog.jsx b/web/src/components/Settings/SettingsDialog.jsx index 5ed27c9..b2247cb 100644 --- a/web/src/components/Settings/SettingsDialog.jsx +++ b/web/src/components/Settings/SettingsDialog.jsx @@ -43,6 +43,54 @@ import { import defaultSettings from './defaultSettings' import { a11yProps, TabPanel } from './tabComponents' +const SliderInput = ({ + isProMode, + title, + value, + setValue, + sliderMin, + sliderMax, + inputMin, + inputMax, + step = 1, + onBlurCallback, +}) => { + const onBlur = ({ target: { value } }) => { + if (value < inputMin) return setValue(inputMin) + if (value > inputMax) return setValue(inputMax) + + onBlurCallback && onBlurCallback(value) + } + + const onInputChange = ({ target: { value } }) => setValue(value === '' ? '' : Number(value)) + const onSliderChange = (_, newValue) => setValue(newValue) + + return ( + <> +
{title}
+ + + + + + + {isProMode && ( + + + + )} + + + ) +} + export default function SettingsDialog({ handleClose }) { const { t } = useTranslation() const fullScreen = useMediaQuery('@media (max-width:930px)') @@ -123,13 +171,6 @@ export default function SettingsDialog({ handleClose }) { 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)) return ( @@ -190,67 +231,29 @@ export default function SettingsDialog({ handleClose }) { -
-
Размер кеша
+ setCacheSize(Math.round(value / 8) * 8)} + /> - - - setCacheSize(newValue)} - step={8} - /> - - - {isProMode && ( - - - - )} - -
- -
-
Кеш предзагрузки
- - - - setCachePercentage(newValue)} - /> - - - {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' }} - /> - - )} - -
+