mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-10-26 19:01:39 -04:00
Antenna calculator: harden wavelength/MHz input handlers.
Clear stale results when wavelength is emptied or invalid, and reject non-finite overflow values so NaN is never displayed or persisted.
This commit is contained in:
parent
2fbf0a9b0f
commit
ef6d470f52
1 changed files with 15 additions and 2 deletions
|
|
@ -217,18 +217,31 @@ export function DipoleAntennaCalculator() {
|
|||
const handleMhzChange = (e, {value}) => {
|
||||
setMhzInputValue(value);
|
||||
const parsed = parseFloat(value);
|
||||
setMhz(value && parsed > 0 ? parsed : 0);
|
||||
// Require a finite positive frequency so overflow (e.g. 1e999 → Infinity) does not stick.
|
||||
setMhz(value && Number.isFinite(parsed) && parsed > 0 ? parsed : 0);
|
||||
localStorage.setItem(mhzStorageKey, value);
|
||||
}
|
||||
|
||||
const handleWaveChange = (e, {value}) => {
|
||||
setWaveInputValue(value);
|
||||
const parsed = parseFloat(value);
|
||||
if (value && parsed > 0) {
|
||||
if (value && Number.isFinite(parsed) && parsed > 0) {
|
||||
const newMhz = frequencyMhzFromWavelengthMeters(parsed);
|
||||
if (newMhz === null) {
|
||||
// Conversion failed (should not happen for finite positive λ); treat as invalid.
|
||||
setMhz(0);
|
||||
setMhzInputValue('');
|
||||
localStorage.setItem(mhzStorageKey, '');
|
||||
return;
|
||||
}
|
||||
setMhz(newMhz);
|
||||
setMhzInputValue(roundDigits(newMhz));
|
||||
localStorage.setItem(mhzStorageKey, String(roundDigits(newMhz)));
|
||||
} else {
|
||||
// Cleared / zero / non-finite wavelength: drop stale MHz and table results.
|
||||
setMhz(0);
|
||||
setMhzInputValue('');
|
||||
localStorage.setItem(mhzStorageKey, '');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue