mirror of
https://github.com/Sonarr/Sonarr.git
synced 2026-04-19 21:46:43 -04:00
cf6b21aef6
Closes #6378
42 lines
1.2 KiB
JavaScript
42 lines
1.2 KiB
JavaScript
import _ from 'lodash';
|
|
import getSectionState from 'Utilities/State/getSectionState';
|
|
import updateSectionState from 'Utilities/State/updateSectionState';
|
|
|
|
function createSetSettingValueReducer(section) {
|
|
return (state, { payload }) => {
|
|
if (section === payload.section) {
|
|
const { name, value, isFloat } = payload;
|
|
const newState = getSectionState(state, section);
|
|
newState.pendingChanges = Object.assign({}, newState.pendingChanges);
|
|
|
|
const currentValue = newState.item ? newState.item[name] : null;
|
|
const pendingState = newState.pendingChanges;
|
|
|
|
let parsedValue = null;
|
|
|
|
if (_.isNumber(currentValue) && value != null) {
|
|
// Use isFloat property to determine parsing method
|
|
if (isFloat) {
|
|
parsedValue = parseFloat(value);
|
|
} else {
|
|
parsedValue = parseInt(value);
|
|
}
|
|
} else {
|
|
parsedValue = value;
|
|
}
|
|
|
|
if (currentValue === parsedValue) {
|
|
delete pendingState[name];
|
|
} else {
|
|
pendingState[name] = parsedValue;
|
|
}
|
|
|
|
return updateSectionState(state, section, newState);
|
|
}
|
|
|
|
return state;
|
|
};
|
|
}
|
|
|
|
export default createSetSettingValueReducer;
|