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

View File

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

View File

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

View File

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

View File

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

View File

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