Skip to content

Commit 1fe91ed

Browse files
fix: handle mauto for quality value on saving
1 parent b0c2099 commit 1fe91ed

File tree

2 files changed

+5
-29
lines changed

2 files changed

+5
-29
lines changed

assets/src/dashboard/parts/connected/settings/Compression.js

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ import {
2424
import { useSelect } from '@wordpress/data';
2525
import { useEffect } from '@wordpress/element';
2626

27-
import { useRef } from '@wordpress/element';
28-
2927
/**
3028
* Internal dependencies.
3129
*/
@@ -46,7 +44,7 @@ const Compression = ({
4644
return value;
4745
}
4846

49-
if ( 'auto' === value ) {
47+
if ( 'auto' === value || 'mauto' === value ) {
5048
return 80;
5149
}
5250

@@ -65,7 +63,6 @@ const Compression = ({
6563
return 80;
6664
};
6765

68-
const manualQualityRef = useRef( getQuality( settings.quality ) );
6966
const {
7067
sampleImages,
7168
isLoading
@@ -88,35 +85,13 @@ const Compression = ({
8885
const compressionMode = settings[ 'compression_mode' ];
8986
const isRetinaEnabled = 'disabled' !== settings[ 'retina_images' ];
9087

91-
useEffect( () => {
92-
if ( isAutoQualityEnabled ) {
93-
return;
94-
}
95-
96-
manualQualityRef.current = getQuality( settings.quality );
97-
}, [ isAutoQualityEnabled, settings.quality ]);
9888
const updateOption = ( option, value ) => {
9989
setCanSave( true );
10090
const data = { ...settings };
10191
data[ option ] = value ? 'enabled' : 'disabled';
10292
setSettings( data );
10393
};
10494

105-
const handleAutoQualityToggle = value => {
106-
setCanSave( true );
107-
const data = { ...settings };
108-
data.autoquality = value ? 'enabled' : 'disabled';
109-
if ( value ) {
110-
manualQualityRef.current = getQuality( settings.quality );
111-
data.quality = 'mauto';
112-
} else {
113-
const manualQuality = manualQualityRef.current ?? getQuality( settings.quality );
114-
manualQualityRef.current = manualQuality;
115-
data.quality = manualQuality;
116-
}
117-
setSettings( data );
118-
};
119-
12095
const loadSample = () => {
12196
setIsSampleLoading( true );
12297

@@ -133,7 +108,6 @@ const Compression = ({
133108
setCanSave( true );
134109
const data = { ...settings };
135110
data.quality = value;
136-
manualQualityRef.current = value;
137111
setSettings( data );
138112
};
139113

@@ -333,7 +307,7 @@ const Compression = ({
333307
'is-disabled': isLoading
334308
}
335309
) }
336-
onChange={ handleAutoQualityToggle }
310+
onChange={ value => updateOption( 'autoquality', value ) }
337311
/>
338312
</BaseControl>
339313

inc/settings.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,9 @@ public function parse_settings( $new_settings ) {
278278
$sanitized_value = $this->to_bound_integer( $value, 100, 5000 );
279279
break;
280280
case 'quality':
281-
$sanitized_value = $this->to_bound_integer( $value, 50, 100 );
281+
if ( 'mauto' !== $value ) {
282+
$sanitized_value = $this->to_bound_integer( $value, 50, 100 );
283+
}
282284
break;
283285
case 'wm_id':
284286
$sanitized_value = intval( $value );

0 commit comments

Comments
 (0)