Disable disallowed settings (#461)

This commit is contained in:
schroda
2023-11-19 00:10:30 +01:00
committed by GitHub
parent eda682d9ab
commit 1fd9b4e744
6 changed files with 80 additions and 85 deletions

View File

@@ -33,6 +33,7 @@ type BaseProps = {
valueUnit: string; valueUnit: string;
handleUpdate: (value: number) => void; handleUpdate: (value: number) => void;
showSlider?: never; showSlider?: never;
disabled?: boolean;
}; };
type PropsWithSlider = Omit<BaseProps, 'defaultValue' | 'minValue' | 'maxValue' | 'showSlider'> & type PropsWithSlider = Omit<BaseProps, 'defaultValue' | 'minValue' | 'maxValue' | 'showSlider'> &
@@ -53,6 +54,7 @@ export const NumberSetting = ({
valueUnit, valueUnit,
handleUpdate, handleUpdate,
showSlider, showSlider,
disabled = false,
}: Props) => { }: Props) => {
const { t } = useTranslation(); const { t } = useTranslation();
@@ -94,7 +96,7 @@ export const NumberSetting = ({
return ( return (
<> <>
<ListItemButton onClick={() => setIsDialogOpen(true)}> <ListItemButton disabled={disabled} onClick={() => setIsDialogOpen(true)}>
{settingIcon ? <ListItemIcon>{settingIcon}</ListItemIcon> : null} {settingIcon ? <ListItemIcon>{settingIcon}</ListItemIcon> : null}
<ListItemText <ListItemText
primary={settingTitle} primary={settingTitle}

View File

@@ -24,6 +24,7 @@ export const TextSetting = ({
handleChange, handleChange,
isPassword = false, isPassword = false,
placeholder = '', placeholder = '',
disabled = false,
}: { }: {
settingName: string; settingName: string;
dialogDescription?: string; dialogDescription?: string;
@@ -31,6 +32,7 @@ export const TextSetting = ({
handleChange: (value: string) => void; handleChange: (value: string) => void;
isPassword?: boolean; isPassword?: boolean;
placeholder?: string; placeholder?: string;
disabled?: boolean;
}) => { }) => {
const { t } = useTranslation(); const { t } = useTranslation();
@@ -64,7 +66,7 @@ export const TextSetting = ({
return ( return (
<> <>
<ListItemButton onClick={() => setIsDialogOpen(true)}> <ListItemButton disabled={disabled} onClick={() => setIsDialogOpen(true)}>
<ListItemText <ListItemText
primary={settingName} primary={settingName}
secondary={isPassword ? value?.replace(/./g, '*') : value ?? t('global.label.loading')} secondary={isPassword ? value?.replace(/./g, '*') : value ?? t('global.label.loading')}

View File

@@ -46,18 +46,17 @@ export const DownloadAheadSetting = () => {
/> />
</ListItemSecondaryAction> </ListItemSecondaryAction>
</ListItem> </ListItem>
{shouldDownloadAhead ? (
<NumberSetting <NumberSetting
settingTitle={t('download.settings.download_ahead.label.unread_chapters_to_download')} settingTitle={t('download.settings.download_ahead.label.unread_chapters_to_download')}
settingValue={ settingValue={
downloadAheadLimit downloadAheadLimit !== undefined
? t('download.settings.download_ahead.label.value', { ? t('download.settings.download_ahead.label.value', {
chapters: downloadAheadLimit, chapters: downloadAheadLimit,
count: downloadAheadLimit, count: downloadAheadLimit,
}) })
: undefined : undefined
} }
value={downloadAheadLimit} value={downloadAheadLimit ?? DEFAULT_LIMIT}
minValue={MIN_LIMIT} minValue={MIN_LIMIT}
maxValue={MAX_LIMIT} maxValue={MAX_LIMIT}
defaultValue={DEFAULT_LIMIT} defaultValue={DEFAULT_LIMIT}
@@ -65,8 +64,8 @@ export const DownloadAheadSetting = () => {
dialogTitle={t('download.settings.download_ahead.label.unread_chapters_to_download')} dialogTitle={t('download.settings.download_ahead.label.unread_chapters_to_download')}
valueUnit={t('chapter.title')} valueUnit={t('chapter.title')}
handleUpdate={updateSetting} handleUpdate={updateSetting}
disabled={!shouldDownloadAhead}
/> />
) : null}
</List> </List>
); );
}; };

View File

@@ -42,17 +42,16 @@ export const GlobalUpdateSettingsInterval = () => {
<Switch edge="end" checked={doAutoUpdates} onChange={(e) => setDoAutoUpdates(e.target.checked)} /> <Switch edge="end" checked={doAutoUpdates} onChange={(e) => setDoAutoUpdates(e.target.checked)} />
</ListItemSecondaryAction> </ListItemSecondaryAction>
</ListItem> </ListItem>
{doAutoUpdates ? (
<NumberSetting <NumberSetting
settingTitle={t('library.settings.global_update.auto_update.interval.label.title')} settingTitle={t('library.settings.global_update.auto_update.interval.label.title')}
settingValue={ settingValue={
autoUpdateIntervalHours autoUpdateIntervalHours !== undefined
? t('library.settings.global_update.auto_update.interval.label.value', { ? t('library.settings.global_update.auto_update.interval.label.value', {
hours: autoUpdateIntervalHours, hours: autoUpdateIntervalHours,
}) })
: undefined : undefined
} }
value={autoUpdateIntervalHours} value={autoUpdateIntervalHours ?? DEFAULT_INTERVAL_HOURS}
minValue={MIN_INTERVAL_HOURS} minValue={MIN_INTERVAL_HOURS}
maxValue={MAX_INTERVAL_HOURS} maxValue={MAX_INTERVAL_HOURS}
defaultValue={DEFAULT_INTERVAL_HOURS} defaultValue={DEFAULT_INTERVAL_HOURS}
@@ -60,8 +59,8 @@ export const GlobalUpdateSettingsInterval = () => {
dialogTitle={t('library.settings.global_update.auto_update.interval.label.title')} dialogTitle={t('library.settings.global_update.auto_update.interval.label.title')}
valueUnit={t('global.time.hour_short')} valueUnit={t('global.time.hour_short')}
handleUpdate={updateSetting} handleUpdate={updateSetting}
disabled={!doAutoUpdates}
/> />
) : null}
</List> </List>
); );
}; };

View File

@@ -92,20 +92,17 @@ export const DownloadSettings = () => {
/> />
</ListItemSecondaryAction> </ListItemSecondaryAction>
</ListItem> </ListItem>
{downloadSettings?.autoDownloadNewChapters ? ( <ListItem disabled={!downloadSettings?.autoDownloadNewChapters}>
<ListItem> <ListItemText primary={t('download.settings.auto_download.label.ignore_with_unread_chapters')} />
<ListItemText
primary={t('download.settings.auto_download.label.ignore_with_unread_chapters')}
/>
<ListItemSecondaryAction> <ListItemSecondaryAction>
<Switch <Switch
edge="end" edge="end"
checked={downloadSettings.excludeEntryWithUnreadChapters} checked={!!downloadSettings?.excludeEntryWithUnreadChapters}
onChange={(e) => updateSetting('excludeEntryWithUnreadChapters', e.target.checked)} onChange={(e) => updateSetting('excludeEntryWithUnreadChapters', e.target.checked)}
disabled={!downloadSettings?.autoDownloadNewChapters}
/> />
</ListItemSecondaryAction> </ListItemSecondaryAction>
</ListItem> </ListItem>
) : null}
</List> </List>
<List <List
subheader={ subheader={

View File

@@ -175,20 +175,18 @@ export const ServerSettings = () => {
/> />
</ListItemSecondaryAction> </ListItemSecondaryAction>
</ListItem> </ListItem>
{!!serverSettings?.socksProxyEnabled && (
<>
<TextSetting <TextSetting
settingName={t('settings.server.socks_proxy.label.host')} settingName={t('settings.server.socks_proxy.label.host')}
value={serverSettings.socksProxyHost} value={serverSettings?.socksProxyHost}
handleChange={(proxyHost) => updateSetting('socksProxyHost', proxyHost)} handleChange={(proxyHost) => updateSetting('socksProxyHost', proxyHost)}
disabled={!serverSettings?.socksProxyEnabled}
/> />
<TextSetting <TextSetting
settingName={t('settings.server.socks_proxy.label.port')} settingName={t('settings.server.socks_proxy.label.port')}
value={serverSettings.socksProxyPort} value={serverSettings?.socksProxyPort}
handleChange={(proxyPort) => updateSetting('socksProxyPort', proxyPort)} handleChange={(proxyPort) => updateSetting('socksProxyPort', proxyPort)}
disabled={!serverSettings?.socksProxyEnabled}
/> />
</>
)}
</List> </List>
<List <List
subheader={ subheader={
@@ -207,21 +205,19 @@ export const ServerSettings = () => {
/> />
</ListItemSecondaryAction> </ListItemSecondaryAction>
</ListItem> </ListItem>
{!!serverSettings?.basicAuthEnabled && (
<>
<TextSetting <TextSetting
settingName={t('settings.server.auth.basic.label.username')} settingName={t('settings.server.auth.basic.label.username')}
value={serverSettings?.basicAuthUsername} value={serverSettings?.basicAuthUsername}
handleChange={(authUsername) => updateSetting('basicAuthUsername', authUsername)} handleChange={(authUsername) => updateSetting('basicAuthUsername', authUsername)}
disabled={!serverSettings?.basicAuthEnabled}
/> />
<TextSetting <TextSetting
settingName={t('settings.server.auth.basic.label.password')} settingName={t('settings.server.auth.basic.label.password')}
value={serverSettings?.basicAuthPassword} value={serverSettings?.basicAuthPassword}
isPassword isPassword
handleChange={(authPassword) => updateSetting('basicAuthPassword', authPassword)} handleChange={(authPassword) => updateSetting('basicAuthPassword', authPassword)}
disabled={!serverSettings?.basicAuthEnabled}
/> />
</>
)}
</List> </List>
<List <List
subheader={ subheader={