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:
csawatzky 2026-03-25 15:45:59 -06:00
parent a288c9503a
commit ce41a2dc05
16 changed files with 188 additions and 178 deletions

View file

@ -21,7 +21,7 @@ import { describeMeasurement } from "pbHelpers/MeasurementDescriber";
import { pond, quack } from "protobuf-ts/pond"; import { pond, quack } from "protobuf-ts/pond";
import { useGlobalState, useInteractionsAPI, useSnackbar } from "providers"; import { useGlobalState, useInteractionsAPI, useSnackbar } from "providers";
import React, { useEffect, useState } from "react"; import React, { useEffect, useState } from "react";
import { avg, fahrenheitToCelsius, getTemperatureUnit } from "utils"; import { avg, fahrenheitToCelsius } from "utils";
import { makeStyles } from "@mui/styles"; import { makeStyles } from "@mui/styles";
import { Mark } from "@mui/material/Slider/useSlider.types"; import { Mark } from "@mui/material/Slider/useSlider.types";
@ -131,7 +131,7 @@ export default function BinConditioningInteraction(props: Props) {
temp && temp &&
hum 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 //the emc calc needs the temp to be in celsius
temp = fahrenheitToCelsius(temp); temp = fahrenheitToCelsius(temp);
} }
@ -139,7 +139,7 @@ export default function BinConditioningInteraction(props: Props) {
setBaseEMC(emc === hum ? undefined : emc); setBaseEMC(emc === hum ? undefined : emc);
} }
}, [sliderVals, grain]); }, [sliderVals, grain, user]);
const updateInteraction = () => { const updateInteraction = () => {
interactionAPI interactionAPI
@ -178,7 +178,7 @@ export default function BinConditioningInteraction(props: Props) {
let marks: Mark[] = []; let marks: Mark[] = [];
if (condition.measurementType === quack.MeasurementType.MEASUREMENT_TYPE_TEMPERATURE) { 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"; labelTail = "°F";
} else { } else {
labelTail = "°C"; labelTail = "°C";
@ -220,7 +220,7 @@ export default function BinConditioningInteraction(props: Props) {
quack.MeasurementType.MEASUREMENT_TYPE_TEMPERATURE quack.MeasurementType.MEASUREMENT_TYPE_TEMPERATURE
) { ) {
if ( if (
getTemperatureUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT user.tempUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT
) { ) {
return value.toFixed(1) + "°F"; return value.toFixed(1) + "°F";
} else { } else {

View file

@ -61,7 +61,7 @@ import { pond } from "protobuf-ts/pond";
import { useBinAPI, useBinYardAPI, useGlobalState, useLibraCartProxyAPI } from "providers"; import { useBinAPI, useBinYardAPI, useGlobalState, useLibraCartProxyAPI } from "providers";
import React, { useCallback, useEffect, useState } from "react"; import React, { useCallback, useEffect, useState } from "react";
// import { useHistory } from "react-router"; // import { useHistory } from "react-router";
import { getDistanceUnit, or, getTemperatureUnit, getGrainUnit } from "utils"; import { getDistanceUnit, or, getGrainUnit } from "utils";
import { makeStyles } from "@mui/styles"; import { makeStyles } from "@mui/styles";
import { useNavigate } from "react-router-dom"; import { useNavigate } from "react-router-dom";
import BinSelector from "./BinSelector"; import BinSelector from "./BinSelector";
@ -290,7 +290,7 @@ export default function BinSettings(props: Props) {
let high = initForm.highTemp ?? 20; let high = initForm.highTemp ?? 20;
let low = initForm.lowTemp ?? 10; let low = initForm.lowTemp ?? 10;
let target = initForm.inventory?.targetTemperature ?? 15; 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)); high = parseFloat((high * 1.8 + 32).toFixed(2));
low = parseFloat((low * 1.8 + 32).toFixed(2)); low = parseFloat((low * 1.8 + 32).toFixed(2));
target = parseFloat((target * 1.8 + 32).toFixed(2)); target = parseFloat((target * 1.8 + 32).toFixed(2));
@ -364,7 +364,7 @@ export default function BinSettings(props: Props) {
} else { } else {
setInitialized(false); setInitialized(false);
} }
}, [bin, open, mode, openedBinYard]); }, [bin, open, mode, openedBinYard, user]);
useEffect(() => { useEffect(() => {
if (mode === "remove") { if (mode === "remove") {
@ -2308,7 +2308,7 @@ export default function BinSettings(props: Props) {
onChange={event => { onChange={event => {
let value = event?.target.value; let value = event?.target.value;
let valueC = 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); valueC = ((Number(value) - 32) * (5 / 9)).toFixed(2);
} }
@ -2320,7 +2320,7 @@ export default function BinSettings(props: Props) {
InputProps={{ InputProps={{
endAdornment: ( endAdornment: (
<InputAdornment position="end"> <InputAdornment position="end">
{getTemperatureUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT {user.tempUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT
? "F" ? "F"
: "C"} : "C"}
</InputAdornment> </InputAdornment>
@ -2348,7 +2348,7 @@ export default function BinSettings(props: Props) {
onChange={event => { onChange={event => {
let value = event?.target.value; let value = event?.target.value;
let valueC = 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); valueC = ((Number(value) - 32) * (5 / 9)).toFixed(2);
} }
setLowTempC(+valueC); setLowTempC(+valueC);
@ -2357,7 +2357,7 @@ export default function BinSettings(props: Props) {
InputProps={{ InputProps={{
endAdornment: ( endAdornment: (
<InputAdornment position="end"> <InputAdornment position="end">
{getTemperatureUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT {user.tempUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT
? "F" ? "F"
: "C"} : "C"}
</InputAdornment> </InputAdornment>
@ -2383,7 +2383,7 @@ export default function BinSettings(props: Props) {
onChange={event => { onChange={event => {
let value = event?.target.value; let value = event?.target.value;
let valueC = 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); valueC = ((Number(value) - 32) * (5 / 9)).toFixed(2);
} }
setHighTempC(+valueC); setHighTempC(+valueC);
@ -2392,7 +2392,7 @@ export default function BinSettings(props: Props) {
InputProps={{ InputProps={{
endAdornment: ( endAdornment: (
<InputAdornment position="end"> <InputAdornment position="end">
{getTemperatureUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT {user.tempUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT
? "F" ? "F"
: "C"} : "C"}
</InputAdornment> </InputAdornment>

View file

@ -24,7 +24,7 @@ import Co2Icon from "products/CommonIcons/co2Icon";
import { pond, quack } from "protobuf-ts/pond"; import { pond, quack } from "protobuf-ts/pond";
import { useBinAPI, useGlobalState, useSnackbar } from "providers"; import { useBinAPI, useGlobalState, useSnackbar } from "providers";
import React, { useEffect, useState } from "react"; import React, { useEffect, useState } from "react";
import { avg, getTemperatureUnit } from "utils"; import { avg } from "utils";
import { makeStyles } from "@mui/styles"; import { makeStyles } from "@mui/styles";
import { Mark } from "@mui/material/Slider/useSlider.types"; import { Mark } from "@mui/material/Slider/useSlider.types";
import { CO2 } from "models/CO2"; import { CO2 } from "models/CO2";
@ -134,7 +134,7 @@ export default function BinStorageConditions(props: Props) {
const binAPI = useBinAPI(); const binAPI = useBinAPI();
const { openSnack } = useSnackbar(); const { openSnack } = useSnackbar();
const { bin, headspaceCO2, cables } = props; const { bin, headspaceCO2, cables } = props;
const [{as}] = useGlobalState() const [{as, user}] = useGlobalState()
const [sliderTemps, setSliderTemps] = useState<number[]>([-40, 40]); 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 //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); const [missingTopNodeWarning, setMissingTopNodeWarning] = useState(false);
@ -233,7 +233,7 @@ export default function BinStorageConditions(props: Props) {
} }
setTempTargets(tempCounts); setTempTargets(tempCounts);
let tempVal = bin.settings.inventory?.targetTemperature ?? 0; 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; tempVal = tempVal * 1.8 + 32;
} }
setTargetTemp(tempVal.toFixed(1)); setTargetTemp(tempVal.toFixed(1));
@ -244,7 +244,7 @@ export default function BinStorageConditions(props: Props) {
setEmcTargets(emcCounts); setEmcTargets(emcCounts);
setTargetEMC(bin.settings.inventory?.targetMoisture.toFixed(1) ?? ""); setTargetEMC(bin.settings.inventory?.targetMoisture.toFixed(1) ?? "");
setEmcDeviation(bin.settings.inventory?.moistureTargetDeviation.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 that watches for changes in the target emc and deviation to update the targets
useEffect(() => { useEffect(() => {
@ -301,7 +301,7 @@ export default function BinStorageConditions(props: Props) {
settings.highTemp = sliderTemps[1]; settings.highTemp = sliderTemps[1];
if (settings.inventory) { if (settings.inventory) {
let tempVal = parseFloat(targetTemp); 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); tempVal = Math.fround(((tempVal - 32) * 5) / 9);
} }
settings.inventory.targetTemperature = tempVal; settings.inventory.targetTemperature = tempVal;
@ -376,14 +376,14 @@ export default function BinStorageConditions(props: Props) {
let mark: Mark[] = []; let mark: Mark[] = [];
if (averageTemp) { if (averageTemp) {
let temp = averageTemp; let temp = averageTemp;
if (getTemperatureUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT) { if (user.tempUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT) {
temp = temp * 1.8 + 32; temp = temp * 1.8 + 32;
} }
mark = [ mark = [
{ {
label: customMark( label: customMark(
temp.toFixed(1) + temp.toFixed(1) +
(getTemperatureUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT (user.tempUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT
? "°F" ? "°F"
: "°C"), : "°C"),
"AVG" "AVG"
@ -422,7 +422,7 @@ export default function BinStorageConditions(props: Props) {
InputProps={{ InputProps={{
endAdornment: ( endAdornment: (
<InputAdornment position="end"> <InputAdornment position="end">
{getTemperatureUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT {user.tempUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT
? "°F" ? "°F"
: "°C"} : "°C"}
</InputAdornment> </InputAdornment>
@ -451,7 +451,7 @@ export default function BinStorageConditions(props: Props) {
max={sliderEdge} max={sliderEdge}
valueLabelDisplay="on" valueLabelDisplay="on"
valueLabelFormat={value => { 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 * 9) / 5 + 32).toFixed(1) + "°F";
} }
return value.toFixed(1) + "°C"; return value.toFixed(1) + "°C";

View file

@ -40,7 +40,7 @@ import { FullScreen, useFullScreenHandle } from "react-full-screen";
import moment, { Moment } from "moment"; import moment, { Moment } from "moment";
import ResponsiveDialog from "common/ResponsiveDialog"; import ResponsiveDialog from "common/ResponsiveDialog";
import { getThemeType } from "theme"; import { getThemeType } from "theme";
import { getGrainUnit, getTemperatureUnit, or } from "utils"; import { getGrainUnit, or } from "utils";
import { useBinAPI } from "providers/pond/binAPI"; import { useBinAPI } from "providers/pond/binAPI";
import BindaptIcon from "products/Bindapt/BindaptIcon"; import BindaptIcon from "products/Bindapt/BindaptIcon";
import { import {
@ -605,7 +605,7 @@ export default function BinVisualizer(props: Props) {
break; break;
} }
if (valC) { if (valC) {
if (getTemperatureUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT) { if (user.tempUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT) {
temp = CtoF(valC).toFixed(1) + "°F"; temp = CtoF(valC).toFixed(1) + "°F";
} else { } else {
temp = valC.toFixed(1) + "°C"; temp = valC.toFixed(1) + "°C";
@ -705,7 +705,7 @@ export default function BinVisualizer(props: Props) {
break; break;
} }
if (valC) { 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 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 { } else {
temp = Math.abs(valC).toFixed(1) + "°C"; temp = Math.abs(valC).toFixed(1) + "°C";
@ -1676,7 +1676,7 @@ export default function BinVisualizer(props: Props) {
fontWeight: 650, fontWeight: 650,
color: tempColour color: tempColour
}}> }}>
{ambient?.getTempString(getTemperatureUnit())} {ambient?.getTempString(user.tempUnit())}
</Typography> </Typography>
</Box> </Box>
<Box display="flex" marginY={1}> <Box display="flex" marginY={1}>

View file

@ -19,7 +19,6 @@ import { sameComponentID } from "pbHelpers/Component";
import moment from "moment"; import moment from "moment";
import { lowerCase } from "lodash"; import { lowerCase } from "lodash";
import { describeMeasurement } from "pbHelpers/MeasurementDescriber"; import { describeMeasurement } from "pbHelpers/MeasurementDescriber";
import { fahrenheitToCelsius, getTemperatureUnit } from "utils";
import { GetGrainExtensionMap } from "grain"; import { GetGrainExtensionMap } from "grain";
import { PromiseProgress, Stage, Step as PromiseStep } from "common/PromiseProgress"; import { PromiseProgress, Stage, Step as PromiseStep } from "common/PromiseProgress";
@ -76,7 +75,7 @@ export default function ModeChangeDialog(props: Props){
changeOutdoorHumidity, changeOutdoorHumidity,
presets presets
} = props } = props
const [{as}] = useGlobalState() const [{as, user}] = useGlobalState()
const [componentSets, setComponentSets] = useState<ComponentSet[]>([]) const [componentSets, setComponentSets] = useState<ComponentSet[]>([])
const interactionAPI = useInteractionsAPI() const interactionAPI = useInteractionsAPI()
const componentAPI = useComponentAPI(); const componentAPI = useComponentAPI();
@ -296,7 +295,7 @@ if (!selectedDevice) return;
conditions.push(humidityCondition); 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 //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; temp = Math.round((temp * (9 / 5) + 32) * 100) / 100;
} }
let tempVal = describeMeasurement( let tempVal = describeMeasurement(
@ -392,7 +391,7 @@ if (!selectedDevice) return;
conditions.push(fanConditionOne); 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 //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; tempPreset = Math.round((tempPreset * (9 / 5) + 32) * 100) / 100;
} }
let tempVal = describeMeasurement( let tempVal = describeMeasurement(
@ -631,7 +630,7 @@ if (!selectedDevice) return;
InputProps={{ InputProps={{
endAdornment: ( endAdornment: (
<InputAdornment position="end"> <InputAdornment position="end">
{getTemperatureUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT {user.tempUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT
? "°F" ? "°F"
: "℃"} : "℃"}
</InputAdornment> </InputAdornment>

View file

@ -614,7 +614,7 @@ export default function ResponsiveTable<T extends Object>(props: Props<T>) {
<TableHead className={stickyHeader ? classes.stickyHeader : undefined}> <TableHead className={stickyHeader ? classes.stickyHeader : undefined}>
{customElement && {customElement &&
<TableRow> <TableRow>
<TableCell colSpan={10000} sx={{ border: "none" }}> <TableCell colSpan={11} sx={{ border: "none" }}>
{customElement} {customElement}
</TableCell> </TableCell>
</TableRow> </TableRow>

View file

@ -33,7 +33,6 @@ import { describeMeasurement } from "pbHelpers/MeasurementDescriber";
import { pond, quack } from "protobuf-ts/pond"; import { pond, quack } from "protobuf-ts/pond";
import React, { useEffect, useState } from "react"; import React, { useEffect, useState } from "react";
import CableTopNodeSummary from "bin/CableTopNodeSummary"; import CableTopNodeSummary from "bin/CableTopNodeSummary";
import { getTemperatureUnit } from "utils";
import { DevicePreset } from "models/DevicePreset"; import { DevicePreset } from "models/DevicePreset";
import { Ambient } from "models/Ambient"; import { Ambient } from "models/Ambient";
import { useGlobalState } from "providers"; import { useGlobalState } from "providers";
@ -182,7 +181,7 @@ export default function DevicePresets(props: DevicePresetsProps) {
const [heaters, setHeaters] = useState<Controller[]>([]); const [heaters, setHeaters] = useState<Controller[]>([]);
const [fans, setFans] = useState<Component[]>([]); const [fans, setFans] = useState<Component[]>([]);
//const [subscribeBinToAutoTopNode, setSubscribeBinToAutoTopNode] = useState(false); //const [subscribeBinToAutoTopNode, setSubscribeBinToAutoTopNode] = useState(false);
const [{as}] = useGlobalState(); const [{as, user}] = useGlobalState();
useEffect(() => { useEffect(() => {
if (deviceComponents.get(deviceIndex.toString())) return; if (deviceComponents.get(deviceIndex.toString())) return;
@ -445,7 +444,7 @@ export default function DevicePresets(props: DevicePresetsProps) {
conditions.push(fanConditionOne); 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 //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; tempPreset = Math.round((tempPreset * (9 / 5) + 32) * 100) / 100;
} }
let tempVal = describeMeasurement( let tempVal = describeMeasurement(
@ -541,7 +540,7 @@ export default function DevicePresets(props: DevicePresetsProps) {
} }
//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 //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; temp = Math.round((temp * (9 / 5) + 32) * 100) / 100;
} }
let tempVal = describeMeasurement( let tempVal = describeMeasurement(

View file

@ -18,10 +18,9 @@ import { cloneDeep } from "lodash";
import { DevicePreset } from "models/DevicePreset"; import { DevicePreset } from "models/DevicePreset";
import { ObjectTypeString } from "objects/ObjectDescriber"; import { ObjectTypeString } from "objects/ObjectDescriber";
import { pond } from "protobuf-ts/pond"; import { pond } from "protobuf-ts/pond";
import { useSnackbar } from "providers"; import { useGlobalState, useSnackbar } from "providers";
import { useDevicePresetAPI } from "providers/pond/devicePresetAPI"; import { useDevicePresetAPI } from "providers/pond/devicePresetAPI";
import React, { useEffect, useState } from "react"; import React, { useEffect, useState } from "react";
import { getTemperatureUnit } from "utils";
interface Props { interface Props {
preset: DevicePreset; preset: DevicePreset;
@ -54,6 +53,7 @@ export default function DevicePresetCard(props: Props) {
const [humString, setHumString] = useState("0"); const [humString, setHumString] = useState("0");
const [hum, setHum] = useState(0); const [hum, setHum] = useState(0);
const isMobile = useMobile(); const isMobile = useMobile();
const [{user}] = useGlobalState();
useEffect(() => { useEffect(() => {
setPresetName(preset.name); setPresetName(preset.name);
@ -63,11 +63,11 @@ export default function DevicePresetCard(props: Props) {
setHum(preset.settings.humidity); setHum(preset.settings.humidity);
setHumString(preset.settings.humidity.toString()); setHumString(preset.settings.humidity.toString());
let displayTemp = preset.settings.temperature.toString(); let displayTemp = preset.settings.temperature.toString();
if (getTemperatureUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT) { if (user.tempUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT) {
displayTemp = ((preset.settings.temperature * 9) / 5 + 32).toFixed(); displayTemp = ((preset.settings.temperature * 9) / 5 + 32).toFixed();
} }
setTempString(displayTemp); setTempString(displayTemp);
}, [preset]); }, [preset, user]);
const saveNewPreset = () => { const saveNewPreset = () => {
let typestring; let typestring;
@ -296,7 +296,7 @@ export default function DevicePresetCard(props: Props) {
InputProps={{ InputProps={{
endAdornment: ( endAdornment: (
<InputAdornment position="end"> <InputAdornment position="end">
{getTemperatureUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT {user.tempUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT
? "°F" ? "°F"
: "°C"} : "°C"}
</InputAdornment> </InputAdornment>
@ -307,7 +307,7 @@ export default function DevicePresetCard(props: Props) {
onChange={e => { onChange={e => {
if (!isNaN(+e.target.value)) { if (!isNaN(+e.target.value)) {
let temp = +e.target.value; let temp = +e.target.value;
if (getTemperatureUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT) { if (user.tempUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT) {
temp = Math.round((((temp - 32) * 5) / 9) * 10) / 10; temp = Math.round((((temp - 32) * 5) / 9) * 10) / 10;
} }
setTempC(temp); setTempC(temp);
@ -324,7 +324,7 @@ export default function DevicePresetCard(props: Props) {
max={40} max={40}
valueLabelDisplay="auto" valueLabelDisplay="auto"
valueLabelFormat={value => { valueLabelFormat={value => {
if (getTemperatureUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT) { if (user.tempUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT) {
return ((value * 9) / 5 + 32).toFixed() + "°F"; return ((value * 9) / 5 + 32).toFixed() + "°F";
} }
return value.toFixed() + "°C"; return value.toFixed() + "°C";
@ -350,7 +350,7 @@ export default function DevicePresetCard(props: Props) {
max={40} max={40}
valueLabelDisplay="auto" valueLabelDisplay="auto"
valueLabelFormat={value => { valueLabelFormat={value => {
if (getTemperatureUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT) { if (user.tempUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT) {
return ((value * 9) / 5 + 32).toFixed() + "°F"; return ((value * 9) / 5 + 32).toFixed() + "°F";
} }
return value.toFixed() + "°C"; return value.toFixed() + "°C";
@ -371,7 +371,7 @@ export default function DevicePresetCard(props: Props) {
InputProps={{ InputProps={{
endAdornment: ( endAdornment: (
<InputAdornment position="end"> <InputAdornment position="end">
{getTemperatureUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT {user.tempUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT
? "°F" ? "°F"
: "°C"} : "°C"}
</InputAdornment> </InputAdornment>
@ -382,7 +382,7 @@ export default function DevicePresetCard(props: Props) {
onChange={e => { onChange={e => {
if (!isNaN(+e.target.value)) { if (!isNaN(+e.target.value)) {
let temp = +e.target.value; let temp = +e.target.value;
if (getTemperatureUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT) { if (user.tempUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT) {
temp = Math.round((((temp - 32) * 5) / 9) * 10) / 10; temp = Math.round((((temp - 32) * 5) / 9) * 10) / 10;
} }
setTempC(temp); setTempC(temp);

View file

@ -11,7 +11,6 @@ import { pond } from "protobuf-ts/pond"
import { quack } from "protobuf-ts/quack" import { quack } from "protobuf-ts/quack"
import { useGlobalState } from "providers" import { useGlobalState } from "providers"
import { useEffect, useState } from "react" import { useEffect, useState } from "react"
import { getTemperatureUnit } from "utils"
interface Props { interface Props {
@ -190,7 +189,7 @@ export default function GateDeltaTempGraph(props: Props){
<span> <span>
{"Delta Temp: "} {"Delta Temp: "}
<span style={{ color: recent.value > 0 ? warmingColour : coolingColour, fontWeight: 500 }}> <span style={{ color: recent.value > 0 ? warmingColour : coolingColour, fontWeight: 500 }}>
{recent.value.toFixed(2) + (getTemperatureUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT ? " °F" : " °C")} {recent.value.toFixed(2) + (user.tempUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT ? " °F" : " °C")}
</span> </span>
<br /> <br />
</span> </span>
@ -213,8 +212,8 @@ export default function GateDeltaTempGraph(props: Props){
<SingleSetAreaChart <SingleSetAreaChart
data={data} data={data}
tooltipLabel="Delta Temp" tooltipLabel="Delta Temp"
tooltipUnit={getTemperatureUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT ? " °F" : " °C"} tooltipUnit={user.tempUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT ? " °F" : " °C"}
yAxisLabel={"Delta T" + (getTemperatureUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT ? " °F" : " °C")} yAxisLabel={"Delta T" + (user.tempUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT ? " °F" : " °C")}
colourAboveZero={{colour: warmingColour, label: "Heating"}} colourAboveZero={{colour: warmingColour, label: "Heating"}}
colourBelowZero={{colour: coolingColour, label: "Cooling"}}/> colourBelowZero={{colour: coolingColour, label: "Cooling"}}/>
</Card> </Card>

View file

@ -17,7 +17,6 @@ import moment from "moment";
import { pond } from "protobuf-ts/pond"; import { pond } from "protobuf-ts/pond";
import { UnitMeasurement } from "models/UnitMeasurement"; import { UnitMeasurement } from "models/UnitMeasurement";
import { quack } from "protobuf-ts/quack"; import { quack } from "protobuf-ts/quack";
import { getTemperatureUnit } from "utils";
import { teal } from "@mui/material/colors"; import { teal } from "@mui/material/colors";
import { react } from "@babel/types"; import { react } from "@babel/types";
import { getDeviceStateHelper } from "pbHelpers/DeviceState"; import { getDeviceStateHelper } from "pbHelpers/DeviceState";
@ -229,7 +228,7 @@ export default function GateList(props: Props) {
}) })
if(ambientTemp && outletTemp){ if(ambientTemp && outletTemp){
let deltaTemp = outletTemp - ambientTemp let deltaTemp = outletTemp - ambientTemp
display = deltaTemp.toFixed(2) + (getTemperatureUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT ? "°F" : "°C") display = deltaTemp.toFixed(2) + (user.tempUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT ? "°F" : "°C")
}else{ }else{
display = "Sensor Missing" display = "Sensor Missing"
} }

View file

@ -101,4 +101,8 @@ export class User {
} }
return this.settings.features.includes(flag); return this.settings.features.includes(flag);
} }
public tempUnit(): pond.TemperatureUnit {
return this.settings.temperatureUnit
}
} }

View file

@ -2,12 +2,12 @@ import { Column } from "common/ResponsiveTable";
import { Option } from "common/SearchSelect"; import { Option } from "common/SearchSelect";
import GrainDescriber from "grain/GrainDescriber"; import GrainDescriber from "grain/GrainDescriber";
//import { Column } from "material-table"; //import { Column } from "material-table";
import { Bin, BinYard, Field } from "models"; import { Bin, BinYard, Field, User } from "models";
//import { Gate } from "models/Gate"; //import { Gate } from "models/Gate";
import { GrainBag } from "models/GrainBag"; import { GrainBag } from "models/GrainBag";
//import { ObjectHeater } from "models/ObjectHeater"; //import { ObjectHeater } from "models/ObjectHeater";
import { pond } from "protobuf-ts/pond"; import { pond } from "protobuf-ts/pond";
import { getDistanceUnit, getTemperatureUnit } from "utils"; import { getDistanceUnit } from "utils";
interface Sort { interface Sort {
order: string; //what to send to the backend list to sort by order: string; //what to send to the backend list to sort by
@ -20,6 +20,8 @@ export interface ObjectExtension {
isTransactionObject: boolean; isTransactionObject: boolean;
//this will define the columns to be used for the object in a material table //this will define the columns to be used for the object in a material table
tableColumns: Column<any>[]; tableColumns: Column<any>[];
// Optional factory so columns can depend on the active user settings (units, formatting, etc.)
getTableColumns?: (user?: User) => Column<any>[];
//this map will match the title of the column to what the backend needs to perform the ordering //this map will match the title of the column to what the backend needs to perform the ordering
tableSort: Map<string, Sort>; tableSort: Map<string, Sort>;
} }
@ -32,6 +34,113 @@ const defaultObject: ObjectExtension = {
tableSort: new Map() tableSort: new Map()
}; };
const binColumns = (user?: User): Column<any>[] => {
const temperatureUnit =
user?.tempUnit() ?? pond.TemperatureUnit.TEMPERATURE_UNIT_CELSIUS;
return [
{
title: "Name",
cellStyle: {padding: "16px"},
render: row => {
return (<div>{row.settings.name}</div>);
}
},
{
title: "Grain",
cellStyle: {padding: "16px"},
render: row => {
let grain = row.settings.inventory?.grainType;
if (grain) {
return GrainDescriber(grain).name;
}
}
},
{
title: "Bin Height",
cellStyle: {padding: "16px"},
render: row => {
let d = row.settings.specs?.heightCm;
if (d) {
if (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS) {
return (d / 100).toFixed(2) + " m";
} else {
return (d / 30.48).toFixed(2) + " ft";
}
}
}
},
{
title: "Bin Diameter",
cellStyle: {padding: "16px"},
render: row => {
let d = row.settings.specs?.diameterCm;
if (d) {
if (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS) {
return (d / 100).toFixed(2) + " m";
} else {
return (d / 30.48).toFixed(2) + " ft";
}
}
}
},
{
title: "Custom Grain Name",
cellStyle: {padding: "16px"},
render: row => {
return row.settings.inventory?.customTypeName;
}
},
{
title: "Grain Variant",
cellStyle: {padding: "16px"},
render: row => {
return row.settings.inventory?.grainSubtype;
}
},
{
title: "Grain Bushels",
cellStyle: {padding: "16px"},
render: row => {
return (<div>{row.settings.inventory ? isNaN(row.settings.inventory.grainBushels) ? 0 : row.settings.inventory.grainBushels : 0}</div>);
}
},
{
title: "Grain Capacity",
cellStyle: {padding: "16px"},
render: row => {
return row.settings.specs?.bushelCapacity;
}
},
{
title: "High Temp Warning",
cellStyle: {padding: "16px"},
render: row => {
let t = row.settings.highTemp;
if (t) {
if (temperatureUnit === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT) {
return (t * 1.8 + 32).toFixed(2) + " °F";
}
return t.toFixed(2) + " °C";
}
}
},
{
title: "Low Temp Warning",
cellStyle: {padding: "16px"},
render: row => {
let t = row.settings.lowTemp;
if (t) {
if (temperatureUnit === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT) {
return (t * 1.8 + 32).toFixed(2) + " °F";
}
return t.toFixed(2) + " °C";
}
}
}
] as Column<Bin>[];
};
export const ObjectExtensions: Map<pond.ObjectType, ObjectExtension> = new Map([ export const ObjectExtensions: Map<pond.ObjectType, ObjectExtension> = new Map([
[pond.ObjectType.OBJECT_TYPE_UNKNOWN, defaultObject], [pond.ObjectType.OBJECT_TYPE_UNKNOWN, defaultObject],
[ [
@ -50,109 +159,8 @@ export const ObjectExtensions: Map<pond.ObjectType, ObjectExtension> = new Map([
name: "Bin", name: "Bin",
inventoryGroup: "grain", inventoryGroup: "grain",
isTransactionObject: true, isTransactionObject: true,
tableColumns: [ tableColumns: binColumns(),
{ getTableColumns: (user?: User) => binColumns(user),
title: "Name",
cellStyle: {padding: "16px"},
render: row => {
return (<div>{row.settings.name}</div>);
}
},
{
title: "Grain",
cellStyle: {padding: "16px"},
render: row => {
let grain = row.settings.inventory?.grainType;
if (grain) {
return GrainDescriber(grain).name;
}
}
},
{
title: "Bin Height",
cellStyle: {padding: "16px"},
render: row => {
let d = row.settings.specs?.heightCm;
if (d) {
if (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS) {
return (d / 100).toFixed(2) + " m";
} else {
return (d / 30.48).toFixed(2) + " ft";
}
}
}
},
{
title: "Bin Diameter",
cellStyle: {padding: "16px"},
render: row => {
let d = row.settings.specs?.diameterCm;
if (d) {
if (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS) {
return (d / 100).toFixed(2) + " m";
} else {
return (d / 30.48).toFixed(2) + " ft";
}
}
}
},
{
title: "Custom Grain Name",
cellStyle: {padding: "16px"},
render: row => {
return row.settings.inventory?.customTypeName;
}
},
{
title: "Grain Variant",
cellStyle: {padding: "16px"},
render: row => {
return row.settings.inventory?.grainSubtype;
}
},
{
title: "Grain Bushels",
cellStyle: {padding: "16px"},
render: row => {
return (<div>{row.settings.inventory ? isNaN(row.settings.inventory.grainBushels) ? 0 : row.settings.inventory.grainBushels : 0}</div>);
}
},
{
title: "Grain Capacity",
cellStyle: {padding: "16px"},
render: row => {
return row.settings.specs?.bushelCapacity;
}
},
{
title: "High Temp Warning",
cellStyle: {padding: "16px"},
render: row => {
let t = row.settings.highTemp;
if (t) {
if (getTemperatureUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT) {
return (t * 1.8 + 32).toFixed(2) + " °F";
} else {
return t.toFixed(2) + " °C";
}
}
}
},
{
title: "Low Temp Warning",
cellStyle: {padding: "16px"},
render: row => {
let t = row.settings.lowTemp;
if (t) {
if (getTemperatureUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT) {
return (t * 1.8 + 32).toFixed(2) + " °F";
} else {
return t.toFixed(2) + " °C";
}
}
}
}
] as Column<Bin>[],
tableSort: new Map([ tableSort: new Map([
["Name", { order: "name", numerical: false }], ["Name", { order: "name", numerical: false }],
["Grain", { order: "inventory.grainType", numerical: false }], ["Grain", { order: "inventory.grainType", numerical: false }],
@ -708,8 +716,7 @@ export const ObjectExtensions: Map<pond.ObjectType, ObjectExtension> = new Map([
]); ]);
export default function ObjectDescriber(type: pond.ObjectType): ObjectExtension { export default function ObjectDescriber(type: pond.ObjectType): ObjectExtension {
let describer = ObjectExtensions.get(type); return ObjectExtensions.get(type) ?? defaultObject;
return describer ? describer : defaultObject;
} }
/** /**
@ -745,7 +752,8 @@ export function SearchableObjects(): Option[] {
Object.values(pond.ObjectType).forEach(obj => { Object.values(pond.ObjectType).forEach(obj => {
if (typeof obj !== "string") { if (typeof obj !== "string") {
let ext = ObjectDescriber(obj); let ext = ObjectDescriber(obj);
if (ext.tableColumns.length > 0) { const columns = ext.getTableColumns ? ext.getTableColumns() : ext.tableColumns;
if (columns.length > 0) {
options.push({ options.push({
label: ext.name, label: ext.name,
value: obj value: obj

View file

@ -1,6 +1,5 @@
import { Box, Button, Grid2 as Grid } from "@mui/material"; import { Box, Button, Grid2 as Grid } from "@mui/material";
// import { getTableIcons } from "common/ResponsiveTable"; // import { getTableIcons } from "common/ResponsiveTable";
import SearchBar from "common/SearchBar";
import SearchSelect, { Option } from "common/SearchSelect"; import SearchSelect, { Option } from "common/SearchSelect";
// import MaterialTable, { MTableToolbar } from "material-table"; // import MaterialTable, { MTableToolbar } from "material-table";
// import { Bin, BinYard, Field } from "models"; // import { Bin, BinYard, Field } from "models";
@ -22,9 +21,8 @@ import {
import { useCallback, useEffect, useState } from "react"; import { useCallback, useEffect, useState } from "react";
import TeamSearch from "teams/TeamSearch"; import TeamSearch from "teams/TeamSearch";
import BulkBinSettings from "./bulkEditForms/bulkBinSettings"; import BulkBinSettings from "./bulkEditForms/bulkBinSettings";
import BulkGrainBagSettings from "./bulkEditForms/bulkGrainBagSettings";
import ResponsiveTable from "common/ResponsiveTable"; import ResponsiveTable from "common/ResponsiveTable";
import { cloneDeep, indexOf } from "lodash"; import { cloneDeep } from "lodash";
//import BulkGateSettings from "./bulkEditForms/bulkGateSettings"; //import BulkGateSettings from "./bulkEditForms/bulkGateSettings";
interface customButton { interface customButton {
@ -61,6 +59,9 @@ export default function ObjectTable(props: Props) {
const [selectedUser, setSelectedUser] = useState<string>(as ?? user.id()); const [selectedUser, setSelectedUser] = useState<string>(as ?? user.id());
const [selectedPageRows, setSelectedPageRows] = useState<Map<number, number[]>>(new Map())//key is the page value is an array of row indexes for that page const [selectedPageRows, setSelectedPageRows] = useState<Map<number, number[]>>(new Map())//key is the page value is an array of row indexes for that page
const [tableLoading, setTableLoading] = useState(false); const [tableLoading, setTableLoading] = useState(false);
const objectExtension = ObjectDescriber(currentType);
const columns = objectExtension.getTableColumns ? objectExtension.getTableColumns(user) : objectExtension.tableColumns;
//the api's to load all the objects available to look at in this table //the api's to load all the objects available to look at in this table
const binAPI = useBinAPI(); const binAPI = useBinAPI();
const binyardAPI = useBinYardAPI(); const binyardAPI = useBinYardAPI();
@ -366,7 +367,7 @@ export default function ObjectTable(props: Props) {
<ResponsiveTable <ResponsiveTable
rows={tableData} rows={tableData}
columns={ObjectDescriber(currentType).tableColumns} columns={columns}
onRowClick={rowClickFunction} onRowClick={rowClickFunction}
total={objectTotal} total={objectTotal}
pageSize={pageSize} pageSize={pageSize}
@ -383,7 +384,7 @@ export default function ObjectTable(props: Props) {
key="objectList" key="objectList"
title={ObjectDescriber(currentType).name} title={ObjectDescriber(currentType).name}
icons={getTableIcons()} icons={getTableIcons()}
columns={ObjectDescriber(currentType).tableColumns} columns={ObjectDescriber(currentType, user).tableColumns}
data={tableData} data={tableData}
page={tablePage} page={tablePage}
totalCount={objectTotal} totalCount={objectTotal}
@ -399,10 +400,10 @@ export default function ObjectTable(props: Props) {
}} }}
onOrderChange={(by, direction) => { onOrderChange={(by, direction) => {
if (by !== -1) { if (by !== -1) {
let colName = ObjectDescriber(currentType).tableColumns[by].title?.toString(); let colName = ObjectDescriber(currentType, user).tableColumns[by].title?.toString();
let order; let order;
if (colName) { if (colName) {
order = ObjectDescriber(currentType).tableSort.get(colName); order = ObjectDescriber(currentType, user).tableSort.get(colName);
setCurrentOrder(order?.order); setCurrentOrder(order?.order);
setCurrentDirection(direction); setCurrentDirection(direction);
setIsNumerical(order?.numerical); setIsNumerical(order?.numerical);

View file

@ -4,7 +4,7 @@ import { GrainOptions } from "grain";
import { pond } from "protobuf-ts/pond"; import { pond } from "protobuf-ts/pond";
import { useBinAPI, useGlobalState, useSnackbar } from "providers"; import { useBinAPI, useGlobalState, useSnackbar } from "providers";
import React, { useState } from "react"; import React, { useState } from "react";
import { fahrenheitToCelsius, getDistanceUnit, getTemperatureUnit } from "utils"; import { fahrenheitToCelsius, getDistanceUnit } from "utils";
interface Props { interface Props {
selectedBins: pond.Bin[]; selectedBins: pond.Bin[];
@ -19,7 +19,7 @@ export default function BulkBinSettings(props: Props) {
const gridItemWidth = 3; const gridItemWidth = 3;
// bin settings variables // bin settings variables
const [name, setName] = useState<string | undefined>(); const [name, setName] = useState<string | undefined>();
const [{as}] = useGlobalState(); const [{as, user}] = useGlobalState();
const [grainType, setGrainType] = useState<pond.Grain | undefined>(); const [grainType, setGrainType] = useState<pond.Grain | undefined>();
const [grainOption, setGrainOption] = useState<Option | null>(); const [grainOption, setGrainOption] = useState<Option | null>();
const [height, setHeight] = useState<number | undefined>(); const [height, setHeight] = useState<number | undefined>();
@ -43,7 +43,7 @@ export default function BulkBinSettings(props: Props) {
const convertedTemp = (enteredTemp: number) => { const convertedTemp = (enteredTemp: number) => {
let t = enteredTemp; let t = enteredTemp;
if (getTemperatureUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT) { if (user.tempUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT) {
t = fahrenheitToCelsius(enteredTemp); t = fahrenheitToCelsius(enteredTemp);
} }
return t; return t;
@ -204,7 +204,7 @@ export default function BulkBinSettings(props: Props) {
InputProps={{ InputProps={{
endAdornment: ( endAdornment: (
<InputAdornment position="end"> <InputAdornment position="end">
{getTemperatureUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT {user.tempUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT
? "°F" ? "°F"
: "°C"} : "°C"}
</InputAdornment> </InputAdornment>
@ -224,7 +224,7 @@ export default function BulkBinSettings(props: Props) {
InputProps={{ InputProps={{
endAdornment: ( endAdornment: (
<InputAdornment position="end"> <InputAdornment position="end">
{getTemperatureUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT {user.tempUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT
? "°F" ? "°F"
: "°C"} : "°C"}
</InputAdornment> </InputAdornment>

View file

@ -32,7 +32,6 @@ import TemperatureIcon from "component/TemperatureIcon";
import FuelIcon from "products/CommonIcons/fuelIcon"; import FuelIcon from "products/CommonIcons/fuelIcon";
import moment from "moment"; import moment from "moment";
import Warning from "@mui/icons-material/Warning"; import Warning from "@mui/icons-material/Warning";
import { getTemperatureUnit } from "utils";
import ResponsiveDialog from "common/ResponsiveDialog"; import ResponsiveDialog from "common/ResponsiveDialog";
import { useParams } from "react-router-dom"; import { useParams } from "react-router-dom";
@ -286,7 +285,7 @@ export default function Heater() {
const tempUnit = () => { const tempUnit = () => {
let unit = "°C"; let unit = "°C";
if (getTemperatureUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT) { if (user.tempUnit() === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT) {
unit = "°F"; unit = "°F";
} }
return unit; return unit;

View file

@ -13,12 +13,13 @@ import {
yellow yellow
} from "@mui/material/colors"; } from "@mui/material/colors";
import { GraphType } from "common/Graph"; import { GraphType } from "common/Graph";
import { User } from "models";
import { IsCardController } from "products/DeviceProduct"; import { IsCardController } from "products/DeviceProduct";
import { pond } from "protobuf-ts/pond"; import { pond } from "protobuf-ts/pond";
import { quack } from "protobuf-ts/quack"; import { quack } from "protobuf-ts/quack";
import { getTextSecondary } from "theme/text"; import { getTextSecondary } from "theme/text";
// import { getTextSecondary } from "theme"; // import { getTextSecondary } from "theme";
import { getDistanceUnit, getPressureUnit, getTemperatureUnit, roundTo } from "utils"; import { getDistanceUnit, getPressureUnit, roundTo } from "utils";
import { extract } from "utils/types"; import { extract } from "utils/types";
interface Enumeration { interface Enumeration {
@ -64,7 +65,8 @@ export class MeasurementDescriber {
measurementType: quack.MeasurementType, measurementType: quack.MeasurementType,
componentType: quack.ComponentType, componentType: quack.ComponentType,
componentSubtype: number, componentSubtype: number,
product?: pond.DeviceProduct product?: pond.DeviceProduct,
user?: User
) { ) {
this.measurementType = measurementType; this.measurementType = measurementType;
this.details = { this.details = {
@ -87,7 +89,7 @@ export class MeasurementDescriber {
case quack.MeasurementType.MEASUREMENT_TYPE_INVALID: case quack.MeasurementType.MEASUREMENT_TYPE_INVALID:
break; break;
case quack.MeasurementType.MEASUREMENT_TYPE_TEMPERATURE: case quack.MeasurementType.MEASUREMENT_TYPE_TEMPERATURE:
let temperatureUnit = getTemperatureUnit(); let temperatureUnit = user?.tempUnit() ?? pond.TemperatureUnit.TEMPERATURE_UNIT_CELSIUS;
let isFahrenheit = temperatureUnit === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT; let isFahrenheit = temperatureUnit === pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT;
this.details.label = "Temperature"; this.details.label = "Temperature";
this.details.unit = isFahrenheit ? "°F" : "°C"; this.details.unit = isFahrenheit ? "°F" : "°C";