1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

Disable text input if option is disabled

This commit is contained in:
viown 2025-01-14 01:17:56 +03:00
parent ec6e0d368b
commit 30204a4db5

View file

@ -20,9 +20,7 @@ export const action = async ({ request }: ActionFunctionArgs) => {
const { data: config } = await getConfigurationApi(api).getConfiguration(); const { data: config } = await getConfigurationApi(api).getConfiguration();
const enableWarningMessage = formData.get('EnableWarningMessage'); const enableWarningMessage = formData.get('EnableWarningMessage');
if (enableWarningMessage) { config.EnableSlowResponseWarning = enableWarningMessage === 'on';
config.EnableSlowResponseWarning = formData.get('EnableWarningMessage') === 'on';
}
const responseTime = formData.get('SlowResponseTime'); const responseTime = formData.get('SlowResponseTime');
if (responseTime) { if (responseTime) {
@ -44,28 +42,28 @@ const Logs = () => {
const { isPending: isLogEntriesPending, data: logs } = useServerLogs(); const { isPending: isLogEntriesPending, data: logs } = useServerLogs();
const { isPending: isConfigurationPending, data: defaultConfiguration } = useConfiguration(); const { isPending: isConfigurationPending, data: defaultConfiguration } = useConfiguration();
const [ loading, setLoading ] = useState(true); const [ loading, setLoading ] = useState(true);
const [ logOptions, setLogOptions ] = useState<ServerConfiguration>( {} ); const [ configuration, setConfiguration ] = useState<ServerConfiguration>( {} );
useEffect(() => { useEffect(() => {
if (!isConfigurationPending && defaultConfiguration) { if (!isConfigurationPending && defaultConfiguration) {
setLogOptions(defaultConfiguration); setConfiguration(defaultConfiguration);
setLoading(false); setLoading(false);
} }
}, [isConfigurationPending, defaultConfiguration]); }, [isConfigurationPending, defaultConfiguration]);
const setLogWarningMessage = useCallback((_: ChangeEvent<HTMLInputElement>, checked: boolean) => { const setLogWarningMessage = useCallback((_: ChangeEvent<HTMLInputElement>, checked: boolean) => {
setLogOptions({ setConfiguration({
...logOptions, ...configuration,
EnableSlowResponseWarning: checked EnableSlowResponseWarning: checked
}); });
}, [logOptions]); }, [configuration]);
const onResponseTimeChange = useCallback((event: ChangeEvent<HTMLTextAreaElement>) => { const onResponseTimeChange = useCallback((event: ChangeEvent<HTMLTextAreaElement>) => {
setLogOptions({ setConfiguration({
...logOptions, ...configuration,
SlowResponseThresholdMs: parseInt(event.target.value, 10) SlowResponseThresholdMs: parseInt(event.target.value, 10)
}); });
}, [logOptions]); }, [configuration]);
const onSubmit = useCallback(() => { const onSubmit = useCallback(() => {
setIsSubmitting(true); setIsSubmitting(true);
@ -97,7 +95,7 @@ const Logs = () => {
<FormControlLabel <FormControlLabel
control={ control={
<Switch <Switch
checked={logOptions?.EnableSlowResponseWarning} checked={configuration?.EnableSlowResponseWarning}
onChange={setLogWarningMessage} onChange={setLogWarningMessage}
name={'EnableWarningMessage'} name={'EnableWarningMessage'}
/> />
@ -110,7 +108,8 @@ const Logs = () => {
type='number' type='number'
name={'SlowResponseTime'} name={'SlowResponseTime'}
label={globalize.translate('LabelSlowResponseTime')} label={globalize.translate('LabelSlowResponseTime')}
value={logOptions?.SlowResponseThresholdMs} value={configuration?.SlowResponseThresholdMs}
disabled={!configuration?.EnableSlowResponseWarning}
onChange={onResponseTimeChange} onChange={onResponseTimeChange}
/> />