mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-10-26 19:01:39 -04:00
Calculators: never store NaN as the Kelvin temperature.
Clearing the temperature input stored parseFloat('') = NaN, rendering
every Kelvin cell as NaN and persisting the invalid value in localStorage
across reloads. Clearing now falls back to room temperature, non-numeric
input is ignored, and a bad stored value decodes to the default.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
53f9386c85
commit
b172a4c9d6
1 changed files with 13 additions and 1 deletions
|
|
@ -455,15 +455,27 @@ export const calcKelvinMilliVoltDrop = (amps, resistancePerKiloLength, length,
|
|||
const FourWireKelvinCalculator = ({wireType, isSAE, length}) => {
|
||||
const [ampsRange] = useState([1, 5, 10]);
|
||||
// Stored in Celsius; displayed in Fahrenheit when SAE. Default is room temperature.
|
||||
const decodeTemperature = (value) => {
|
||||
const temperature = parseFloat(value);
|
||||
return Number.isFinite(temperature) ? temperature : REFERENCE_TEMPERATURE_C;
|
||||
};
|
||||
const [temperatureC, setTemperatureC] = useLocalStorage(
|
||||
'calculators.kelvin.temperature_c', REFERENCE_TEMPERATURE_C, parseFloat, (num) => num.toString());
|
||||
'calculators.kelvin.temperature_c', REFERENCE_TEMPERATURE_C, decodeTemperature, (num) => num.toString());
|
||||
|
||||
const resistances = isSAE ? resistancesPerKFeet[wireType]
|
||||
: resistancesPerKm[wireType];
|
||||
|
||||
const displayTemperature = isSAE ? roundDigits(temperatureC * 9 / 5 + 32, 1) : roundDigits(temperatureC, 1);
|
||||
const handleTemperatureChange = (value) => {
|
||||
if (value === '') {
|
||||
// Never store NaN; fall back to room temperature when the input is cleared.
|
||||
setTemperatureC(REFERENCE_TEMPERATURE_C);
|
||||
return;
|
||||
}
|
||||
const temperature = parseFloat(value);
|
||||
if (!Number.isFinite(temperature)) {
|
||||
return;
|
||||
}
|
||||
setTemperatureC(isSAE ? (temperature - 32) * 5 / 9 : temperature);
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue