mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-26 01:46:18 -05:00
Using localStorage to store navbar color and calculator values.
This commit is contained in:
parent
11dc370ed9
commit
b643728b96
7 changed files with 81 additions and 53 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import {HelpPopup, roundDigits, Toggle} from "../Common";
|
||||
import {HelpPopup, roundDigits, Toggle, useLocalStorage, useLocalStorageInt} from "../Common";
|
||||
import React, {useState} from "react";
|
||||
import {Form, Header, Segment, Table} from "../Theme";
|
||||
import Grid from "semantic-ui-react/dist/commonjs/collections/Grid";
|
||||
|
|
@ -264,23 +264,15 @@ export const calcPowerLossPercent = (isSAE, volts, amps, resistancePerKiloLength
|
|||
return (voltageDrop / volts) * 100; // Return as a percentage
|
||||
};
|
||||
|
||||
const PowerLossCalculator = ({defaultVolts = 120}) => {
|
||||
const [volts, setVolts] = useState(defaultVolts);
|
||||
const [wireType, setWireType] = useState('solid');
|
||||
const [isSAE, setIsSAE] = useState(true);
|
||||
const [length, setLength] = useState(100);
|
||||
const PowerLossCalculator = ({volts, setVolts}) => {
|
||||
const [wireType, setWireType] = useLocalStorage('calculators.power_loss.wire_type', 'solid');
|
||||
const [isSAE, setIsSAE] = useLocalStorage('calculators.power_loss.is_sae', true);
|
||||
const [length, setLength] = useLocalStorageInt('calculators.power_loss.length', 100);
|
||||
const [ampsRange] = useState([1, 5, 10, 20, 40, 100]);
|
||||
|
||||
const {inverted} = React.useContext(ThemeContext);
|
||||
const warningBackgroundColor = inverted === 'inverted' ? '#332020' : '#ffbebe';
|
||||
|
||||
React.useEffect(() => {
|
||||
// Copy voltage from Ohm's Law calculator.
|
||||
if (defaultVolts > 0) {
|
||||
setVolts(defaultVolts);
|
||||
}
|
||||
}, [defaultVolts]);
|
||||
|
||||
const resistances = isSAE ? resistancesPerKFeet[wireType]
|
||||
: resistancesPerKm[wireType];
|
||||
|
||||
|
|
@ -385,9 +377,9 @@ const PowerLossCalculator = ({defaultVolts = 120}) => {
|
|||
};
|
||||
|
||||
export const ElectricalCalculators = () => {
|
||||
const [volts, setVolts] = React.useState();
|
||||
const [volts, setVolts] = useLocalStorageInt('calculators.electrical.volts', 120);
|
||||
return <Container>
|
||||
<Segment><OhmsLawCalculator setVolts={setVolts}/></Segment>
|
||||
<Segment><PowerLossCalculator defaultVolts={volts}/></Segment>
|
||||
<Segment><PowerLossCalculator volts={volts} setVolts={setVolts}/></Segment>
|
||||
</Container>
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ export function TemperatureCalculator() {
|
|||
const handleInputChange = (e, {name, value}) => {
|
||||
if (value === '') {
|
||||
// User has cleared the input;
|
||||
setState({volt: '', ohm: '', amp: ''});
|
||||
setState({celsius: '', fahrenheit: '', kelvin: ''});
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue