mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
rename SAVE to APPLY, show number of updates - #911
This commit is contained in:
@@ -21,3 +21,29 @@ export const updateValue =
|
||||
[event.target.name]: extractEventValue(event)
|
||||
}));
|
||||
};
|
||||
|
||||
export const updateValueDirty =
|
||||
<S>(origData: any, dirtyFlags: any, setDirtyFlags: any, updateEntity: UpdateEntity<S>) =>
|
||||
(event: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const updated_value = extractEventValue(event);
|
||||
const name = event.target.name;
|
||||
updateEntity((prevState) => ({
|
||||
...prevState,
|
||||
[name]: updated_value
|
||||
}));
|
||||
|
||||
const arr: string[] = dirtyFlags;
|
||||
|
||||
if (origData[name] !== updated_value) {
|
||||
if (!arr.includes(name)) {
|
||||
arr.push(name);
|
||||
}
|
||||
} else {
|
||||
const startIndex = arr.indexOf(name);
|
||||
if (startIndex !== -1) {
|
||||
arr.splice(startIndex, 1);
|
||||
}
|
||||
}
|
||||
|
||||
setDirtyFlags(arr);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user