mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-12-03 13:19:58 -05:00
Guard preset lookup, drop dead Media import and volume*1 no-op
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:
parent
d998bb93a1
commit
342374b97f
1 changed files with 4 additions and 3 deletions
|
|
@ -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]);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue