replacing the getTemperatureUnit function in units that uses the local storage with a function in the user model to just get it from the user settings
This commit is contained in:
parent
a288c9503a
commit
ce41a2dc05
16 changed files with 188 additions and 178 deletions
|
|
@ -21,7 +21,7 @@ import { describeMeasurement } from "pbHelpers/MeasurementDescriber";
|
|||
import { pond, quack } from "protobuf-ts/pond";
|
||||
import { useGlobalState, useInteractionsAPI, useSnackbar } from "providers";
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { avg, fahrenheitToCelsius, getTemperatureUnit } from "utils";
|
||||
import { avg, fahrenheitToCelsius } from "utils";
|
||||
import { makeStyles } from "@mui/styles";
|
||||
import { Mark } from "@mui/material/Slider/useSlider.types";
|
||||
|
||||
|
|
@ -131,7 +131,7 @@ export default function BinConditioningInteraction(props: Props) {
|
|||
temp &&
|
||||
hum
|
||||
) {
|
||||
if (getTemperatureUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT) {
|
||||
if (user.tempUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT) {
|
||||
//the emc calc needs the temp to be in celsius
|
||||
temp = fahrenheitToCelsius(temp);
|
||||
}
|
||||
|
|
@ -139,7 +139,7 @@ export default function BinConditioningInteraction(props: Props) {
|
|||
setBaseEMC(emc === hum ? undefined : emc);
|
||||
|
||||
}
|
||||
}, [sliderVals, grain]);
|
||||
}, [sliderVals, grain, user]);
|
||||
|
||||
const updateInteraction = () => {
|
||||
interactionAPI
|
||||
|
|
@ -178,7 +178,7 @@ export default function BinConditioningInteraction(props: Props) {
|
|||
let marks: Mark[] = [];
|
||||
|
||||
if (condition.measurementType === quack.MeasurementType.MEASUREMENT_TYPE_TEMPERATURE) {
|
||||
if (getTemperatureUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT) {
|
||||
if (user.tempUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT) {
|
||||
labelTail = "°F";
|
||||
} else {
|
||||
labelTail = "°C";
|
||||
|
|
@ -220,7 +220,7 @@ export default function BinConditioningInteraction(props: Props) {
|
|||
quack.MeasurementType.MEASUREMENT_TYPE_TEMPERATURE
|
||||
) {
|
||||
if (
|
||||
getTemperatureUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT
|
||||
user.tempUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT
|
||||
) {
|
||||
return value.toFixed(1) + "°F";
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ import { pond } from "protobuf-ts/pond";
|
|||
import { useBinAPI, useBinYardAPI, useGlobalState, useLibraCartProxyAPI } from "providers";
|
||||
import React, { useCallback, useEffect, useState } from "react";
|
||||
// import { useHistory } from "react-router";
|
||||
import { getDistanceUnit, or, getTemperatureUnit, getGrainUnit } from "utils";
|
||||
import { getDistanceUnit, or, getGrainUnit } from "utils";
|
||||
import { makeStyles } from "@mui/styles";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import BinSelector from "./BinSelector";
|
||||
|
|
@ -290,7 +290,7 @@ export default function BinSettings(props: Props) {
|
|||
let high = initForm.highTemp ?? 20;
|
||||
let low = initForm.lowTemp ?? 10;
|
||||
let target = initForm.inventory?.targetTemperature ?? 15;
|
||||
if (getTemperatureUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT) {
|
||||
if (user.tempUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT) {
|
||||
high = parseFloat((high * 1.8 + 32).toFixed(2));
|
||||
low = parseFloat((low * 1.8 + 32).toFixed(2));
|
||||
target = parseFloat((target * 1.8 + 32).toFixed(2));
|
||||
|
|
@ -364,7 +364,7 @@ export default function BinSettings(props: Props) {
|
|||
} else {
|
||||
setInitialized(false);
|
||||
}
|
||||
}, [bin, open, mode, openedBinYard]);
|
||||
}, [bin, open, mode, openedBinYard, user]);
|
||||
|
||||
useEffect(() => {
|
||||
if (mode === "remove") {
|
||||
|
|
@ -2308,7 +2308,7 @@ export default function BinSettings(props: Props) {
|
|||
onChange={event => {
|
||||
let value = event?.target.value;
|
||||
let valueC = value;
|
||||
if (getTemperatureUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT) {
|
||||
if (user.tempUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT) {
|
||||
valueC = ((Number(value) - 32) * (5 / 9)).toFixed(2);
|
||||
}
|
||||
|
||||
|
|
@ -2320,7 +2320,7 @@ export default function BinSettings(props: Props) {
|
|||
InputProps={{
|
||||
endAdornment: (
|
||||
<InputAdornment position="end">
|
||||
{getTemperatureUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT
|
||||
{user.tempUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT
|
||||
? "F"
|
||||
: "C"}
|
||||
</InputAdornment>
|
||||
|
|
@ -2348,7 +2348,7 @@ export default function BinSettings(props: Props) {
|
|||
onChange={event => {
|
||||
let value = event?.target.value;
|
||||
let valueC = value;
|
||||
if (getTemperatureUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT) {
|
||||
if (user.tempUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT) {
|
||||
valueC = ((Number(value) - 32) * (5 / 9)).toFixed(2);
|
||||
}
|
||||
setLowTempC(+valueC);
|
||||
|
|
@ -2357,7 +2357,7 @@ export default function BinSettings(props: Props) {
|
|||
InputProps={{
|
||||
endAdornment: (
|
||||
<InputAdornment position="end">
|
||||
{getTemperatureUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT
|
||||
{user.tempUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT
|
||||
? "F"
|
||||
: "C"}
|
||||
</InputAdornment>
|
||||
|
|
@ -2383,7 +2383,7 @@ export default function BinSettings(props: Props) {
|
|||
onChange={event => {
|
||||
let value = event?.target.value;
|
||||
let valueC = value;
|
||||
if (getTemperatureUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT) {
|
||||
if (user.tempUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT) {
|
||||
valueC = ((Number(value) - 32) * (5 / 9)).toFixed(2);
|
||||
}
|
||||
setHighTempC(+valueC);
|
||||
|
|
@ -2392,7 +2392,7 @@ export default function BinSettings(props: Props) {
|
|||
InputProps={{
|
||||
endAdornment: (
|
||||
<InputAdornment position="end">
|
||||
{getTemperatureUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT
|
||||
{user.tempUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT
|
||||
? "F"
|
||||
: "C"}
|
||||
</InputAdornment>
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ import Co2Icon from "products/CommonIcons/co2Icon";
|
|||
import { pond, quack } from "protobuf-ts/pond";
|
||||
import { useBinAPI, useGlobalState, useSnackbar } from "providers";
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { avg, getTemperatureUnit } from "utils";
|
||||
import { avg } from "utils";
|
||||
import { makeStyles } from "@mui/styles";
|
||||
import { Mark } from "@mui/material/Slider/useSlider.types";
|
||||
import { CO2 } from "models/CO2";
|
||||
|
|
@ -134,7 +134,7 @@ export default function BinStorageConditions(props: Props) {
|
|||
const binAPI = useBinAPI();
|
||||
const { openSnack } = useSnackbar();
|
||||
const { bin, headspaceCO2, cables } = props;
|
||||
const [{as}] = useGlobalState()
|
||||
const [{as, user}] = useGlobalState()
|
||||
const [sliderTemps, setSliderTemps] = useState<number[]>([-40, 40]);
|
||||
//boolean that if a cable is missing its filled to display an icon or something to let the user know not all of the cables have their fill set
|
||||
const [missingTopNodeWarning, setMissingTopNodeWarning] = useState(false);
|
||||
|
|
@ -233,7 +233,7 @@ export default function BinStorageConditions(props: Props) {
|
|||
}
|
||||
setTempTargets(tempCounts);
|
||||
let tempVal = bin.settings.inventory?.targetTemperature ?? 0;
|
||||
if (getTemperatureUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT) {
|
||||
if (user.tempUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT) {
|
||||
tempVal = tempVal * 1.8 + 32;
|
||||
}
|
||||
setTargetTemp(tempVal.toFixed(1));
|
||||
|
|
@ -244,7 +244,7 @@ export default function BinStorageConditions(props: Props) {
|
|||
setEmcTargets(emcCounts);
|
||||
setTargetEMC(bin.settings.inventory?.targetMoisture.toFixed(1) ?? "");
|
||||
setEmcDeviation(bin.settings.inventory?.moistureTargetDeviation.toFixed(1) ?? "");
|
||||
}, [bin, cables]);
|
||||
}, [bin, cables, user]);
|
||||
|
||||
//useEffect that watches for changes in the target emc and deviation to update the targets
|
||||
useEffect(() => {
|
||||
|
|
@ -301,7 +301,7 @@ export default function BinStorageConditions(props: Props) {
|
|||
settings.highTemp = sliderTemps[1];
|
||||
if (settings.inventory) {
|
||||
let tempVal = parseFloat(targetTemp);
|
||||
if (getTemperatureUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT) {
|
||||
if (user.tempUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT) {
|
||||
tempVal = Math.fround(((tempVal - 32) * 5) / 9);
|
||||
}
|
||||
settings.inventory.targetTemperature = tempVal;
|
||||
|
|
@ -376,14 +376,14 @@ export default function BinStorageConditions(props: Props) {
|
|||
let mark: Mark[] = [];
|
||||
if (averageTemp) {
|
||||
let temp = averageTemp;
|
||||
if (getTemperatureUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT) {
|
||||
if (user.tempUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT) {
|
||||
temp = temp * 1.8 + 32;
|
||||
}
|
||||
mark = [
|
||||
{
|
||||
label: customMark(
|
||||
temp.toFixed(1) +
|
||||
(getTemperatureUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT
|
||||
(user.tempUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT
|
||||
? "°F"
|
||||
: "°C"),
|
||||
"AVG"
|
||||
|
|
@ -422,7 +422,7 @@ export default function BinStorageConditions(props: Props) {
|
|||
InputProps={{
|
||||
endAdornment: (
|
||||
<InputAdornment position="end">
|
||||
{getTemperatureUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT
|
||||
{user.tempUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT
|
||||
? "°F"
|
||||
: "°C"}
|
||||
</InputAdornment>
|
||||
|
|
@ -451,7 +451,7 @@ export default function BinStorageConditions(props: Props) {
|
|||
max={sliderEdge}
|
||||
valueLabelDisplay="on"
|
||||
valueLabelFormat={value => {
|
||||
if (getTemperatureUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT) {
|
||||
if (user.tempUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT) {
|
||||
return ((value * 9) / 5 + 32).toFixed(1) + "°F";
|
||||
}
|
||||
return value.toFixed(1) + "°C";
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ import { FullScreen, useFullScreenHandle } from "react-full-screen";
|
|||
import moment, { Moment } from "moment";
|
||||
import ResponsiveDialog from "common/ResponsiveDialog";
|
||||
import { getThemeType } from "theme";
|
||||
import { getGrainUnit, getTemperatureUnit, or } from "utils";
|
||||
import { getGrainUnit, or } from "utils";
|
||||
import { useBinAPI } from "providers/pond/binAPI";
|
||||
import BindaptIcon from "products/Bindapt/BindaptIcon";
|
||||
import {
|
||||
|
|
@ -605,7 +605,7 @@ export default function BinVisualizer(props: Props) {
|
|||
break;
|
||||
}
|
||||
if (valC) {
|
||||
if (getTemperatureUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT) {
|
||||
if (user.tempUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT) {
|
||||
temp = CtoF(valC).toFixed(1) + "°F";
|
||||
} else {
|
||||
temp = valC.toFixed(1) + "°C";
|
||||
|
|
@ -705,7 +705,7 @@ export default function BinVisualizer(props: Props) {
|
|||
break;
|
||||
}
|
||||
if (valC) {
|
||||
if (getTemperatureUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT) {
|
||||
if (user.tempUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT) {
|
||||
temp = Math.abs(valC * 1.8).toFixed(1) + "°F"; //since this is a measurement of change a change in 1 degrre celsius is equivalent to 1.8 fahrenheit
|
||||
} else {
|
||||
temp = Math.abs(valC).toFixed(1) + "°C";
|
||||
|
|
@ -1676,7 +1676,7 @@ export default function BinVisualizer(props: Props) {
|
|||
fontWeight: 650,
|
||||
color: tempColour
|
||||
}}>
|
||||
{ambient?.getTempString(getTemperatureUnit())}
|
||||
{ambient?.getTempString(user.tempUnit())}
|
||||
</Typography>
|
||||
</Box>
|
||||
<Box display="flex" marginY={1}>
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ import { sameComponentID } from "pbHelpers/Component";
|
|||
import moment from "moment";
|
||||
import { lowerCase } from "lodash";
|
||||
import { describeMeasurement } from "pbHelpers/MeasurementDescriber";
|
||||
import { fahrenheitToCelsius, getTemperatureUnit } from "utils";
|
||||
import { GetGrainExtensionMap } from "grain";
|
||||
import { PromiseProgress, Stage, Step as PromiseStep } from "common/PromiseProgress";
|
||||
|
||||
|
|
@ -76,7 +75,7 @@ export default function ModeChangeDialog(props: Props){
|
|||
changeOutdoorHumidity,
|
||||
presets
|
||||
} = props
|
||||
const [{as}] = useGlobalState()
|
||||
const [{as, user}] = useGlobalState()
|
||||
const [componentSets, setComponentSets] = useState<ComponentSet[]>([])
|
||||
const interactionAPI = useInteractionsAPI()
|
||||
const componentAPI = useComponentAPI();
|
||||
|
|
@ -296,7 +295,7 @@ if (!selectedDevice) return;
|
|||
conditions.push(humidityCondition);
|
||||
|
||||
//since the measurement describers function to stored does a conversion into celsius if the users pref is fahrenheit for temperature we need to convert the preset value into fahrenheit
|
||||
if (getTemperatureUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT) {
|
||||
if (user.tempUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT) {
|
||||
temp = Math.round((temp * (9 / 5) + 32) * 100) / 100;
|
||||
}
|
||||
let tempVal = describeMeasurement(
|
||||
|
|
@ -392,7 +391,7 @@ if (!selectedDevice) return;
|
|||
conditions.push(fanConditionOne);
|
||||
|
||||
//since the measurement describers function toStored does a conversion into celsius for temperature if the users pref is fahrenheit we need to convert the preset value into fahrenheit
|
||||
if (getTemperatureUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT) {
|
||||
if (user.tempUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT) {
|
||||
tempPreset = Math.round((tempPreset * (9 / 5) + 32) * 100) / 100;
|
||||
}
|
||||
let tempVal = describeMeasurement(
|
||||
|
|
@ -631,7 +630,7 @@ if (!selectedDevice) return;
|
|||
InputProps={{
|
||||
endAdornment: (
|
||||
<InputAdornment position="end">
|
||||
{getTemperatureUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT
|
||||
{user.tempUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT
|
||||
? "°F"
|
||||
: "℃"}
|
||||
</InputAdornment>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue