Guard preset lookup, drop dead Media import and volume*1 no-op
Some checks are pending
CodeQL / Analyze (push) Waiting to run
Controller Tests / controller-tests (push) Waiting to run
Jest Tests / jest-tests (push) Waiting to run

Address Greptile review on PR #447:
- Fall back to the minimum preset when an unrecognized/stale
  water_calculator_preset is read from localStorage, so a bad persisted
  value can no longer crash the component on mount.
- Remove the unused Media import.
- Simplify the metric branch of waterWeight (volume * 1 -> volume).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Roland 2026-05-28 18:05:03 -06:00
parent d998bb93a1
commit 342374b97f
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680

View file

@ -3,7 +3,6 @@ import {GridColumn, Input, Label, TableBody, TableCell, TableHeader, TableHeader
import Grid from "semantic-ui-react/dist/commonjs/collections/Grid";
import {Form, Header, Segment, Table} from "../Theme";
import {InfoPopup, roundDigits, Toggle, useLocalStorage} from "../Common";
import {Media} from "../../contexts/contexts";
// Pure calculation functions for the Water Storage calculator.
//
@ -54,7 +53,7 @@ export function waterWeight(volume, metric) {
if (!(volume > 0)) {
return null;
}
return metric ? volume * 1 : volume * 8.345;
return metric ? volume : volume * 8.345;
}
/**
@ -217,8 +216,10 @@ export function WaterCalculator() {
DURATION_STOPS.indexOf(14));
// Reset the editable rates to the preset's defaults whenever the preset or unit changes.
// Fall back to the minimum preset if localStorage holds an unrecognized/stale key, so a
// bad persisted value can never crash the component on mount.
React.useEffect(() => {
const p = WATER_PRESETS[preset];
const p = WATER_PRESETS[preset] ?? WATER_PRESETS.minimum;
setRates(metric ? {...p.metric} : {...p.imperial});
}, [preset, metric]);