had cursor replace uses of getDistanceUnit with using the distance unit in the users settings so that it no longer relies on local storage

This commit is contained in:
csawatzky 2026-03-26 09:43:39 -06:00
parent c6bb7aa24a
commit dc54f99abd
20 changed files with 273 additions and 199 deletions

View file

@ -4,7 +4,7 @@ import SearchSelect, { Option } from "common/SearchSelect";
import { useMobile } from "hooks"; import { useMobile } from "hooks";
import { pond } from "protobuf-ts/pond"; import { pond } from "protobuf-ts/pond";
import React, { useEffect, useState } from "react"; import React, { useEffect, useState } from "react";
import { getDistanceUnit } from "utils"; import { useGlobalState } from "providers";
interface Props { interface Props {
optionsChanged: (binOptions: jsonBin[]) => void; optionsChanged: (binOptions: jsonBin[]) => void;
@ -13,6 +13,7 @@ interface Props {
export default function BinSelector(props: Props) { export default function BinSelector(props: Props) {
const { optionsChanged, vertical } = props; const { optionsChanged, vertical } = props;
const [{user}] = useGlobalState();
const isMobile = useMobile(); const isMobile = useMobile();
const [manufacturerOptions, SetManufacturerOptions] = useState<Option[]>([]); const [manufacturerOptions, SetManufacturerOptions] = useState<Option[]>([]);
const [manufacturer, SetManufacturer] = useState<Option | null>(null); const [manufacturer, SetManufacturer] = useState<Option | null>(null);
@ -126,7 +127,7 @@ export default function BinSelector(props: Props) {
}} }}
label={ label={
"Minimum Diameter " + "Minimum Diameter " +
(getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET ? "(ft)" : "(m)") (user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET ? "(ft)" : "(m)")
} }
/> />
</Grid> </Grid>
@ -143,7 +144,7 @@ export default function BinSelector(props: Props) {
}} }}
label={ label={
"Maximum Diameter " + "Maximum Diameter " +
(getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET ? "(ft)" : "(m)") (user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET ? "(ft)" : "(m)")
} }
/> />
</Grid> </Grid>

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, getGrainUnit } from "utils"; import { 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";
@ -269,7 +269,7 @@ export default function BinSettings(props: Props) {
let sidewallHeight = ""; let sidewallHeight = "";
let hopperHeight = ""; let hopperHeight = "";
if (initForm.specs) { if (initForm.specs) {
if (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET) { if (user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET) {
h = (initForm.specs.heightCm * 0.0328).toFixed(2); h = (initForm.specs.heightCm * 0.0328).toFixed(2);
d = (initForm.specs.diameterCm * 0.0328).toFixed(2); d = (initForm.specs.diameterCm * 0.0328).toFixed(2);
if (initForm.specs.advancedDimensions) { if (initForm.specs.advancedDimensions) {
@ -350,7 +350,7 @@ export default function BinSettings(props: Props) {
setMoistureTargetDeviation(initForm.inventory?.moistureTargetDeviation.toString() ?? "0"); setMoistureTargetDeviation(initForm.inventory?.moistureTargetDeviation.toString() ?? "0");
setAutoFillThreshold(initForm.inventory?.autoThreshold ?? 5) setAutoFillThreshold(initForm.inventory?.autoThreshold ?? 5)
let dropDistance = initForm.inventory?.lidarDropCm ?? 0 let dropDistance = initForm.inventory?.lidarDropCm ?? 0
if(getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET){ if(user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET){
dropDistance = Math.round((dropDistance/30.48)*100)/100 dropDistance = Math.round((dropDistance/30.48)*100)/100
} }
setLidarDropDistance(dropDistance) setLidarDropDistance(dropDistance)
@ -475,7 +475,7 @@ export default function BinSettings(props: Props) {
if (form.inventory) { if (form.inventory) {
form.inventory.inventoryControl = inventoryControl form.inventory.inventoryControl = inventoryControl
form.inventory.autoThreshold = autoFillThreshold form.inventory.autoThreshold = autoFillThreshold
form.inventory.lidarDropCm = getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET ? lidarDropDistance * 30.48 : lidarDropDistance form.inventory.lidarDropCm = user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET ? lidarDropDistance * 30.48 : lidarDropDistance
if(form.inventory.grainType !== pond.Grain.GRAIN_CUSTOM){ if(form.inventory.grainType !== pond.Grain.GRAIN_CUSTOM){
form.inventory.customGrain = undefined form.inventory.customGrain = undefined
}else{ }else{
@ -529,7 +529,7 @@ export default function BinSettings(props: Props) {
form.inventory.inventoryControl = inventoryControl form.inventory.inventoryControl = inventoryControl
form.inventory.autoThreshold = autoFillThreshold form.inventory.autoThreshold = autoFillThreshold
//if the users preferences are in feet convert the distance to cm otherwise it was entered as cm so use that //if the users preferences are in feet convert the distance to cm otherwise it was entered as cm so use that
form.inventory.lidarDropCm = getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET ? lidarDropDistance * 30.48 : lidarDropDistance form.inventory.lidarDropCm = user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET ? lidarDropDistance * 30.48 : lidarDropDistance
if(form.inventory.grainType !== pond.Grain.GRAIN_CUSTOM){ if(form.inventory.grainType !== pond.Grain.GRAIN_CUSTOM){
form.inventory.customGrain = undefined form.inventory.customGrain = undefined
}else{ }else{
@ -1099,7 +1099,7 @@ export default function BinSettings(props: Props) {
InputProps={{ InputProps={{
endAdornment: ( endAdornment: (
<InputAdornment position="end"> <InputAdornment position="end">
{getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET ? "ft" : "cm"} {user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET ? "ft" : "cm"}
</InputAdornment> </InputAdornment>
) )
}} }}
@ -1435,7 +1435,7 @@ export default function BinSettings(props: Props) {
let sH = sidewallHeight; let sH = sidewallHeight;
let hH = hopperHeight ?? 0; let hH = hopperHeight ?? 0;
let d = diameter; let d = diameter;
if (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS) { if (user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS) {
tcH = tcH * 3.281; tcH = tcH * 3.281;
sH = sH * 3.281; sH = sH * 3.281;
hH = hH * 3.281; hH = hH * 3.281;
@ -1463,7 +1463,7 @@ export default function BinSettings(props: Props) {
let hopperHeight = formExtension.hopperHeight; let hopperHeight = formExtension.hopperHeight;
let diameter = formExtension.diameter; let diameter = formExtension.diameter;
// if (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET) { // if (user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET) {
// diameterM = (Number(diameterM) * 3.28084).toFixed(2); // diameterM = (Number(diameterM) * 3.28084).toFixed(2);
// heightM = (Number(heightM) * 3.28084).toFixed(2); // heightM = (Number(heightM) * 3.28084).toFixed(2);
// } // }
@ -1552,7 +1552,7 @@ export default function BinSettings(props: Props) {
let d = diameter; let d = diameter;
let valueM = value; let valueM = value;
let dM = diameter; let dM = diameter;
if (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET) { if (user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET) {
valueM = (Number(value) * 0.3048).toFixed(2); valueM = (Number(value) * 0.3048).toFixed(2);
dM = (Number(d) * 0.3048).toFixed(2); dM = (Number(d) * 0.3048).toFixed(2);
} }
@ -1577,7 +1577,7 @@ export default function BinSettings(props: Props) {
InputProps={{ InputProps={{
endAdornment: ( endAdornment: (
<InputAdornment position="end"> <InputAdornment position="end">
{getDistanceUnit() !== pond.DistanceUnit.DISTANCE_UNIT_FEET ? "m" : "ft"} {user.distanceUnit() !== pond.DistanceUnit.DISTANCE_UNIT_FEET ? "m" : "ft"}
</InputAdornment> </InputAdornment>
) )
}} }}
@ -1637,7 +1637,7 @@ export default function BinSettings(props: Props) {
let value = event?.target.value; let value = event?.target.value;
let valueM = value; let valueM = value;
setModelID(0); setModelID(0);
if (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET) { if (user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET) {
valueM = (Number(value) * 0.3048).toFixed(2); valueM = (Number(value) * 0.3048).toFixed(2);
} }
let coneCM = let coneCM =
@ -1674,7 +1674,7 @@ export default function BinSettings(props: Props) {
//need to get the total height in cm //need to get the total height in cm
let totalHeightCM = s + t + h; //the total height in the users units let totalHeightCM = s + t + h; //the total height in the users units
if(getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET){ if(user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET){
totalHeightCM = totalHeightCM * 30.48 //convert from feet to cm totalHeightCM = totalHeightCM * 30.48 //convert from feet to cm
}else{ }else{
totalHeightCM = totalHeightCM * 100 //convert from m to cm totalHeightCM = totalHeightCM * 100 //convert from m to cm
@ -1698,7 +1698,7 @@ export default function BinSettings(props: Props) {
InputProps={{ InputProps={{
endAdornment: ( endAdornment: (
<InputAdornment position="end"> <InputAdornment position="end">
{getDistanceUnit() !== pond.DistanceUnit.DISTANCE_UNIT_FEET {user.distanceUnit() !== pond.DistanceUnit.DISTANCE_UNIT_FEET
? "m" ? "m"
: "ft"} : "ft"}
</InputAdornment> </InputAdornment>
@ -1725,7 +1725,7 @@ export default function BinSettings(props: Props) {
//calculate the new cone height for the roof angle //calculate the new cone height for the roof angle
let coneCM = TriangleOppositeLength(d / 2, angle ?? 0); let coneCM = TriangleOppositeLength(d / 2, angle ?? 0);
let newConeHeight = let newConeHeight =
getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET
? (coneCM / 30.48).toFixed(2) ? (coneCM / 30.48).toFixed(2)
: (coneCM / 100).toFixed(2); : (coneCM / 100).toFixed(2);
@ -1749,7 +1749,7 @@ export default function BinSettings(props: Props) {
//need to get the total height in cm //need to get the total height in cm
let totalHeightCM = s + t + h; //the total height in the users units let totalHeightCM = s + t + h; //the total height in the users units
if(getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET){ if(user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET){
totalHeightCM = totalHeightCM * 30.48 //convert from feet to cm totalHeightCM = totalHeightCM * 30.48 //convert from feet to cm
}else{ }else{
totalHeightCM = totalHeightCM * 100 //convert from m to cm totalHeightCM = totalHeightCM * 100 //convert from m to cm
@ -1786,7 +1786,7 @@ export default function BinSettings(props: Props) {
onChange={event => { onChange={event => {
let value = event?.target.value; let value = event?.target.value;
let valueM = value; let valueM = value;
if (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET) { if (user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET) {
valueM = (Number(value) * 0.3048).toFixed(2); valueM = (Number(value) * 0.3048).toFixed(2);
} }
let ext = cloneDeep(formExtension); let ext = cloneDeep(formExtension);
@ -1811,7 +1811,7 @@ export default function BinSettings(props: Props) {
//need to get the total height in cm //need to get the total height in cm
let totalHeightCM = s + t + h; //the total height in the users units let totalHeightCM = s + t + h; //the total height in the users units
if(getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET){ if(user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET){
totalHeightCM = totalHeightCM * 30.48 //convert from feet to cm totalHeightCM = totalHeightCM * 30.48 //convert from feet to cm
}else{ }else{
totalHeightCM = totalHeightCM * 100 //convert from m to cm totalHeightCM = totalHeightCM * 100 //convert from m to cm
@ -1838,7 +1838,7 @@ export default function BinSettings(props: Props) {
InputProps={{ InputProps={{
endAdornment: ( endAdornment: (
<InputAdornment position="end"> <InputAdornment position="end">
{getDistanceUnit() !== pond.DistanceUnit.DISTANCE_UNIT_FEET {user.distanceUnit() !== pond.DistanceUnit.DISTANCE_UNIT_FEET
? "m" ? "m"
: "ft"} : "ft"}
</InputAdornment> </InputAdornment>
@ -1868,7 +1868,7 @@ export default function BinSettings(props: Props) {
let coneCM = TriangleOppositeLength(d / 2, angle ?? 0); let coneCM = TriangleOppositeLength(d / 2, angle ?? 0);
let newHopperHeight = let newHopperHeight =
getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET
? (coneCM / 30.48).toFixed(2) ? (coneCM / 30.48).toFixed(2)
: (coneCM / 100).toFixed(2); : (coneCM / 100).toFixed(2);
@ -1926,7 +1926,7 @@ export default function BinSettings(props: Props) {
onChange={event => { onChange={event => {
let value = event?.target.value; let value = event?.target.value;
let valueM = value; let valueM = value;
if (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET) { if (user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET) {
valueM = (Number(value) * 0.3048).toFixed(2); valueM = (Number(value) * 0.3048).toFixed(2);
} }
@ -1982,7 +1982,7 @@ export default function BinSettings(props: Props) {
InputProps={{ InputProps={{
endAdornment: ( endAdornment: (
<InputAdornment position="end"> <InputAdornment position="end">
{getDistanceUnit() !== pond.DistanceUnit.DISTANCE_UNIT_FEET {user.distanceUnit() !== pond.DistanceUnit.DISTANCE_UNIT_FEET
? "m" ? "m"
: "ft"} : "ft"}
</InputAdornment> </InputAdornment>
@ -2009,7 +2009,7 @@ export default function BinSettings(props: Props) {
let h = height; let h = height;
let valueM = value; let valueM = value;
let hM = height; let hM = height;
if (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET) { if (user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET) {
valueM = (Number(value) * 0.3048).toFixed(2); valueM = (Number(value) * 0.3048).toFixed(2);
hM = (Number(h) * 0.3048).toFixed(2); hM = (Number(h) * 0.3048).toFixed(2);
} }
@ -2063,7 +2063,7 @@ export default function BinSettings(props: Props) {
InputProps={{ InputProps={{
endAdornment: ( endAdornment: (
<InputAdornment position="end"> <InputAdornment position="end">
{getDistanceUnit() !== pond.DistanceUnit.DISTANCE_UNIT_FEET ? "m" : "ft"} {user.distanceUnit() !== pond.DistanceUnit.DISTANCE_UNIT_FEET ? "m" : "ft"}
</InputAdornment> </InputAdornment>
) )
}} }}
@ -2253,7 +2253,7 @@ export default function BinSettings(props: Props) {
let userHopperHeight = hopperHeight; let userHopperHeight = hopperHeight;
let userDiameter = jsonBin.Diameter; let userDiameter = jsonBin.Diameter;
//since the jsone data is in feet just check if we need to make it in meters //since the jsone data is in feet just check if we need to make it in meters
if (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS) { if (user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS) {
userHeight = userHeight / 3.281; userHeight = userHeight / 3.281;
userDiameter = userDiameter / 3.281; userDiameter = userDiameter / 3.281;
userTopCone = userTopCone / 3.281; userTopCone = userTopCone / 3.281;

View file

@ -2,6 +2,7 @@ import { colors } from "@mui/material";
import { jsonBin } from "common/DataImports/BinCables/BinCableImporter"; import { jsonBin } from "common/DataImports/BinCables/BinCableImporter";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { distanceConversion } from "utils"; import { distanceConversion } from "utils";
import { useGlobalState } from "providers";
interface Props { interface Props {
bin: jsonBin; bin: jsonBin;
@ -22,6 +23,8 @@ export default function SideView(props: Props) {
const dimensionFontSize = 7; const dimensionFontSize = 7;
const gapSize = svgViewBoxSize * 0.05; const gapSize = svgViewBoxSize * 0.05;
const { bin } = props; const { bin } = props;
const [{ user }] = useGlobalState();
const distanceUnit = user.distanceUnit();
const [scale, setScale] = useState(0); //the scale to multiply the bin dimension by in order to determine how long to draw the line const [scale, setScale] = useState(0); //the scale to multiply the bin dimension by in order to determine how long to draw the line
const [hopperHeight, setHopperHeight] = useState(0); const [hopperHeight, setHopperHeight] = useState(0);
const [roofHeight, setRoofHeight] = useState(0); const [roofHeight, setRoofHeight] = useState(0);
@ -194,7 +197,7 @@ export default function SideView(props: Props) {
"bottomText", "bottomText",
svgViewBoxSize / 2, svgViewBoxSize / 2,
y2, y2,
distanceConversion(bin.Diameter).toFixed(1) distanceConversion(bin.Diameter, distanceUnit).toFixed(1)
) )
); );
@ -231,7 +234,7 @@ export default function SideView(props: Props) {
let y2 = (roofHeight + bin.Sidewall) * scale; let y2 = (roofHeight + bin.Sidewall) * scale;
d.push( d.push(
dimensionText("sidewallText", x2, midpoint, distanceConversion(bin.Sidewall).toFixed(1)) dimensionText("sidewallText", x2, midpoint, distanceConversion(bin.Sidewall, distanceUnit).toFixed(1))
); );
d.push( d.push(
dimensionPath( dimensionPath(
@ -270,7 +273,7 @@ export default function SideView(props: Props) {
"peakText", "peakText",
xText, xText,
midpoint, midpoint,
distanceConversion(bin.Sidewall + roofHeight).toFixed(1) distanceConversion(bin.Sidewall + roofHeight, distanceUnit).toFixed(1)
) )
); );
d.push( d.push(
@ -313,7 +316,7 @@ export default function SideView(props: Props) {
"totalText", "totalText",
x2, x2,
midpoint, midpoint,
distanceConversion(roofHeight + bin.Sidewall + hopperHeight).toFixed(1) distanceConversion(roofHeight + bin.Sidewall + hopperHeight, distanceUnit).toFixed(1)
) )
); );
d.push( d.push(

View file

@ -18,7 +18,7 @@ import {
//import MaterialTable from "material-table"; //import MaterialTable from "material-table";
//import { getTableIcons } from "common/ResponsiveTable"; //import { getTableIcons } from "common/ResponsiveTable";
import CableDisplay from "./cableDisplay"; import CableDisplay from "./cableDisplay";
import { distanceConversion, getDistanceUnit } from "utils"; import { distanceConversion } from "utils";
import { pond } from "protobuf-ts/pond"; import { pond } from "protobuf-ts/pond";
import CableQuote from "./cableQuote"; import CableQuote from "./cableQuote";
import { useMobile } from "hooks"; import { useMobile } from "hooks";
@ -33,6 +33,7 @@ import {
} from "common/TrigFunctions"; } from "common/TrigFunctions";
import ResponsiveTable, { Column } from "common/ResponsiveTable"; import ResponsiveTable, { Column } from "common/ResponsiveTable";
import { makeStyles } from "@mui/styles"; import { makeStyles } from "@mui/styles";
import { useGlobalState } from "providers";
const useStyles = makeStyles(() => ({ const useStyles = makeStyles(() => ({
sliderThumb: { sliderThumb: {
@ -56,6 +57,7 @@ export default function CableEstimator() {
//the conversion constant to convert cubic feet to bushels //the conversion constant to convert cubic feet to bushels
const conversionConstantFT = 0.7786; const conversionConstantFT = 0.7786;
const classes = useStyles(); const classes = useStyles();
const [{ user }] = useGlobalState();
const [binOptions, setBinOptions] = useState<jsonBin[]>([]); const [binOptions, setBinOptions] = useState<jsonBin[]>([]);
const [displayedRows, setDisplayedRows] = useState<jsonBin[]>([]); const [displayedRows, setDisplayedRows] = useState<jsonBin[]>([]);
const [tablePage, setTablePage] = useState(0) const [tablePage, setTablePage] = useState(0)
@ -67,21 +69,21 @@ export default function CableEstimator() {
const [quoteOpen, setQuoteOpen] = useState(false); const [quoteOpen, setQuoteOpen] = useState(false);
const [useCustomBin, setUseCustomBin] = useState(false); const [useCustomBin, setUseCustomBin] = useState(false);
const [diameterFormEntry, setDiameterFormEntry] = useState( const [diameterFormEntry, setDiameterFormEntry] = useState(
getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS ? "9.1" : "30" user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS ? "9.1" : "30"
); );
//const [capacityFormEntry, setCapacityFormEntry] = useState("0"); //const [capacityFormEntry, setCapacityFormEntry] = useState("0");
const [ringsFormEntry, setRingsFormEntry] = useState("0"); const [ringsFormEntry, setRingsFormEntry] = useState("0");
const [ringHeightFormEntry, setRingHeightFormEntry] = useState("0"); const [ringHeightFormEntry, setRingHeightFormEntry] = useState("0");
const [ringHeightFt, setRingHeightFt] = useState(0); const [ringHeightFt, setRingHeightFt] = useState(0);
const [sidewallFormEntry, setSidewallFormEntry] = useState( const [sidewallFormEntry, setSidewallFormEntry] = useState(
getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS ? "7" : "23" user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS ? "7" : "23"
); );
const [peakFormEntry, setPeakFormEntry] = useState( const [peakFormEntry, setPeakFormEntry] = useState(
getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS ? "9.1" : "30" user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS ? "9.1" : "30"
); );
//const [eaveToPeakFormEntry, setEaveToPeakFormEntry] = useState("0"); //const [eaveToPeakFormEntry, setEaveToPeakFormEntry] = useState("0");
const [roofAngleFormEntry, setRoofAngleFormEntry] = useState( const [roofAngleFormEntry, setRoofAngleFormEntry] = useState(
getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS ? "7.6" : "25" user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS ? "7.6" : "25"
); );
const [hopperAngleFormEntry, setHopperAngleFormEntry] = useState("0"); const [hopperAngleFormEntry, setHopperAngleFormEntry] = useState("0");
const nodeSpacing = 4; const nodeSpacing = 4;
@ -129,24 +131,40 @@ export default function CableEstimator() {
render: (row: jsonBin) => <Box padding={2}>{row.HopperAngle}</Box> render: (row: jsonBin) => <Box padding={2}>{row.HopperAngle}</Box>
}, },
{ {
title: "Diameter " + (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET ? "(ft)" : "(m)"), title: "Diameter " + (user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET ? "(ft)" : "(m)"),
sortKey: "Diameter", sortKey: "Diameter",
render: (row: jsonBin) => <Box padding={2}>{distanceConversion(row.Diameter).toFixed(2)}</Box> render: (row: jsonBin) => (
<Box padding={2}>
{distanceConversion(row.Diameter, user.distanceUnit()).toFixed(2)}
</Box>
)
}, },
{ {
title: "Sidewall" + (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET ? "(ft)" : "(m)"), title: "Sidewall" + (user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET ? "(ft)" : "(m)"),
sortKey: "Sidewall", sortKey: "Sidewall",
render: (row: jsonBin) => <Box padding={2}>{distanceConversion(row.Sidewall).toFixed(2)}</Box> render: (row: jsonBin) => (
<Box padding={2}>
{distanceConversion(row.Sidewall, user.distanceUnit()).toFixed(2)}
</Box>
)
}, },
{ {
title: "Peak Height" + (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET ? "(ft)" : "(m)"), title: "Peak Height" + (user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET ? "(ft)" : "(m)"),
sortKey: "Peak", sortKey: "Peak",
render: (row: jsonBin) => <Box padding={2}>{distanceConversion(row.Peak).toFixed(2)}</Box> render: (row: jsonBin) => (
<Box padding={2}>
{distanceConversion(row.Peak, user.distanceUnit()).toFixed(2)}
</Box>
)
}, },
{ {
title: "Eave To Peak" + (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET ? "(ft)" : "(m)"), title: "Eave To Peak" + (user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET ? "(ft)" : "(m)"),
sortKey: "EaveToPeak", sortKey: "EaveToPeak",
render: (row: jsonBin) => <Box padding={2}>{distanceConversion(row.EaveToPeak).toFixed(2)}</Box> render: (row: jsonBin) => (
<Box padding={2}>
{distanceConversion(row.EaveToPeak, user.distanceUnit()).toFixed(2)}
</Box>
)
}, },
{ {
title: "Roof Angle", title: "Roof Angle",
@ -545,7 +563,7 @@ export default function CableEstimator() {
InputProps={{ InputProps={{
endAdornment: ( endAdornment: (
<InputAdornment position="end"> <InputAdornment position="end">
{getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS ? "m" : "ft"} {user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS ? "m" : "ft"}
</InputAdornment> </InputAdornment>
) )
}} }}
@ -554,7 +572,7 @@ export default function CableEstimator() {
onChange={e => { onChange={e => {
setDiameterFormEntry(e.target.value); setDiameterFormEntry(e.target.value);
let val = isNaN(parseFloat(e.target.value)) ? 0 : parseFloat(e.target.value); let val = isNaN(parseFloat(e.target.value)) ? 0 : parseFloat(e.target.value);
if (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS) { if (user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS) {
val = val * 3.281; val = val * 3.281;
} }
//when the diameter is changed use the current peak height to adjust the roof angle //when the diameter is changed use the current peak height to adjust the roof angle
@ -577,7 +595,7 @@ export default function CableEstimator() {
InputProps={{ InputProps={{
endAdornment: ( endAdornment: (
<InputAdornment position="end"> <InputAdornment position="end">
{getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS ? "m" : "ft"} {user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS ? "m" : "ft"}
</InputAdornment> </InputAdornment>
) )
}} }}
@ -589,7 +607,7 @@ export default function CableEstimator() {
onChange={e => { onChange={e => {
setPeakFormEntry(e.target.value); setPeakFormEntry(e.target.value);
let val = isNaN(parseFloat(e.target.value)) ? 0 : parseFloat(e.target.value); let val = isNaN(parseFloat(e.target.value)) ? 0 : parseFloat(e.target.value);
if (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS) { if (user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS) {
val = val * 3.281; val = val * 3.281;
} }
//when the peak height is changed use the diameter to calculate the roof angle //when the peak height is changed use the diameter to calculate the roof angle
@ -621,7 +639,7 @@ export default function CableEstimator() {
//use the new number of rings and ring height to get the sidewall height //use the new number of rings and ring height to get the sidewall height
let sidewallFt = val * ringHeightFt; let sidewallFt = val * ringHeightFt;
bin.Sidewall = sidewallFt; bin.Sidewall = sidewallFt;
if (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS) { if (user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS) {
setSidewallFormEntry((sidewallFt / 3.281).toString()); setSidewallFormEntry((sidewallFt / 3.281).toString());
} else { } else {
setSidewallFormEntry(sidewallFt.toString()); setSidewallFormEntry(sidewallFt.toString());
@ -650,7 +668,7 @@ export default function CableEstimator() {
onChange={e => { onChange={e => {
setRingHeightFormEntry(e.target.value); setRingHeightFormEntry(e.target.value);
let inVal = isNaN(parseFloat(e.target.value)) ? 0 : parseFloat(e.target.value); let inVal = isNaN(parseFloat(e.target.value)) ? 0 : parseFloat(e.target.value);
// if (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS) { // if (user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS) {
// val = val * 3.281; // val = val * 3.281;
// } // }
let ringFt = inVal / 12; let ringFt = inVal / 12;
@ -659,7 +677,7 @@ export default function CableEstimator() {
let bin = cloneDeep(customBin); let bin = cloneDeep(customBin);
let sidewallFt = bin.Rings * ringFt; let sidewallFt = bin.Rings * ringFt;
bin.Sidewall = sidewallFt; bin.Sidewall = sidewallFt;
if (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS) { if (user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS) {
setSidewallFormEntry((sidewallFt / 3.281).toString()); setSidewallFormEntry((sidewallFt / 3.281).toString());
} else { } else {
setSidewallFormEntry(sidewallFt.toString()); setSidewallFormEntry(sidewallFt.toString());
@ -683,7 +701,7 @@ export default function CableEstimator() {
InputProps={{ InputProps={{
endAdornment: ( endAdornment: (
<InputAdornment position="end"> <InputAdornment position="end">
{getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS ? "m" : "ft"} {user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS ? "m" : "ft"}
</InputAdornment> </InputAdornment>
) )
}} }}
@ -694,7 +712,7 @@ export default function CableEstimator() {
setSidewallFormEntry(e.target.value); setSidewallFormEntry(e.target.value);
let val = isNaN(parseFloat(e.target.value)) ? 0 : parseFloat(e.target.value); let val = isNaN(parseFloat(e.target.value)) ? 0 : parseFloat(e.target.value);
//if the value entered is meters convert it to feet for the bin //if the value entered is meters convert it to feet for the bin
if (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS) { if (user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS) {
val = val * 3.281; val = val * 3.281;
} }
let bin = cloneDeep(customBin); let bin = cloneDeep(customBin);
@ -733,7 +751,7 @@ export default function CableEstimator() {
let coneHeight = calcConeHeight(bin.Diameter / 2, bin.RoofAngle); let coneHeight = calcConeHeight(bin.Diameter / 2, bin.RoofAngle);
bin.Peak = bin.Sidewall + coneHeight; //assign it as feet bin.Peak = bin.Sidewall + coneHeight; //assign it as feet
let peakHeightDisplay = bin.Sidewall + coneHeight; let peakHeightDisplay = bin.Sidewall + coneHeight;
if (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS) { if (user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS) {
peakHeightDisplay = peakHeightDisplay / 3.281; peakHeightDisplay = peakHeightDisplay / 3.281;
} }
setPeakFormEntry(peakHeightDisplay.toFixed(1)); setPeakFormEntry(peakHeightDisplay.toFixed(1));
@ -762,7 +780,7 @@ export default function CableEstimator() {
let coneHeight = calcConeHeight(bin.Diameter / 2, bin.RoofAngle); let coneHeight = calcConeHeight(bin.Diameter / 2, bin.RoofAngle);
bin.Peak = bin.Sidewall + coneHeight; bin.Peak = bin.Sidewall + coneHeight;
let peakHeightDisplay = bin.Sidewall + coneHeight; let peakHeightDisplay = bin.Sidewall + coneHeight;
if (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS) { if (user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS) {
peakHeightDisplay = peakHeightDisplay / 3.281; peakHeightDisplay = peakHeightDisplay / 3.281;
} }
setPeakFormEntry(peakHeightDisplay.toFixed(1)); setPeakFormEntry(peakHeightDisplay.toFixed(1));
@ -887,7 +905,7 @@ export default function CableEstimator() {
setEaveToPeakFormEntry(e.target.value); setEaveToPeakFormEntry(e.target.value);
let val = isNaN(parseFloat(e.target.value)) ? 0 : parseFloat(e.target.value); let val = isNaN(parseFloat(e.target.value)) ? 0 : parseFloat(e.target.value);
//if the value entered is meters convert it to feet for the bin //if the value entered is meters convert it to feet for the bin
if (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS) { if (user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS) {
val = val * 3.281; val = val * 3.281;
} }
let bin = cloneDeep(customBin); let bin = cloneDeep(customBin);

View file

@ -4,8 +4,8 @@ import ResponsiveTable, { Column } from "common/ResponsiveTable";
//import { getTableIcons } from "common/ResponsiveTable"; //import { getTableIcons } from "common/ResponsiveTable";
//import MaterialTable from "material-table"; //import MaterialTable from "material-table";
import { pond } from "protobuf-ts/pond"; import { pond } from "protobuf-ts/pond";
import { useEffect } from "react"; import { distanceConversion } from "utils";
import { distanceConversion, getDistanceUnit } from "utils"; import { useGlobalState } from "providers";
interface Props { interface Props {
bin: jsonBin; bin: jsonBin;
@ -13,6 +13,7 @@ interface Props {
export default function CableMounting(props: Props) { export default function CableMounting(props: Props) {
const { bin } = props; const { bin } = props;
const [{ user }] = useGlobalState();
// const [tablePage, setTablePage] = useState(0) // const [tablePage, setTablePage] = useState(0)
// const [pageSize, setPageSize] = useState(10) // const [pageSize, setPageSize] = useState(10)
@ -26,15 +27,19 @@ export default function CableMounting(props: Props) {
render: (row: CableSum) => <Box padding={2}>{row.Orbit === 0 ? "Center" : row.Orbit}</Box> render: (row: CableSum) => <Box padding={2}>{row.Orbit === 0 ? "Center" : row.Orbit}</Box>
}, },
{ {
title: "From Center " + (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET ? "(ft)" : "(m)"), title: "From Center " + (user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET ? "(ft)" : "(m)"),
render: (row: CableSum) => ( render: (row: CableSum) => (
<Box padding={2}>{distanceConversion(row.DistanceFromCenter).toFixed(2)}</Box> <Box padding={2}>
{distanceConversion(row.DistanceFromCenter, user.distanceUnit()).toFixed(2)}
</Box>
) )
}, },
{ {
title: "Along Roof" + (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET ? "(ft)" : "(m)"), title: "Along Roof" + (user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET ? "(ft)" : "(m)"),
render: (row: CableSum) => ( render: (row: CableSum) => (
<Box padding={2}>{distanceConversion(roofDist(row.DistanceFromCenter)).toFixed(2)}</Box> <Box padding={2}>
{distanceConversion(roofDist(row.DistanceFromCenter), user.distanceUnit()).toFixed(2)}
</Box>
) )
}, },
{ {

View file

@ -5,6 +5,7 @@ import ResponsiveDialog from "common/ResponsiveDialog";
import { useMobile } from "hooks"; import { useMobile } from "hooks";
import { jsonBin } from "common/DataImports/BinCables/BinCableImporter"; import { jsonBin } from "common/DataImports/BinCables/BinCableImporter";
import PdfContent from "./pdfComponents/pdfContent"; import PdfContent from "./pdfComponents/pdfContent";
import { useGlobalState } from "providers";
interface Props { interface Props {
bin: jsonBin; bin: jsonBin;
@ -14,6 +15,7 @@ interface Props {
export default function CableQuote(props: Props) { export default function CableQuote(props: Props) {
const { open, close, bin } = props; const { open, close, bin } = props;
const [{user}] = useGlobalState();
const isMobil = useMobile(); const isMobil = useMobile();
const pdfStyle = StyleSheet.create({ const pdfStyle = StyleSheet.create({
viewerDesktop: { viewerDesktop: {
@ -27,7 +29,11 @@ export default function CableQuote(props: Props) {
}); });
const pdfDoc = () => { const pdfDoc = () => {
return <AgPDFTemplate content={<PdfContent bin={bin} />} />; return (
<AgPDFTemplate
content={<PdfContent bin={bin} distanceUnit={user.distanceUnit()} />}
/>
);
}; };
return ( return (

View file

@ -3,7 +3,8 @@ import { Box, Typography } from "@mui/material";
//import MaterialTable from "material-table"; //import MaterialTable from "material-table";
import { pond } from "protobuf-ts/pond"; import { pond } from "protobuf-ts/pond";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { distanceConversion, getDistanceUnit } from "utils"; import { distanceConversion } from "utils";
import { useGlobalState } from "providers";
import { Cable, jsonBin } from "common/DataImports/BinCables/BinCableImporter"; import { Cable, jsonBin } from "common/DataImports/BinCables/BinCableImporter";
import { cloneDeep } from "lodash"; import { cloneDeep } from "lodash";
import ResponsiveTable, { Column } from "common/ResponsiveTable"; import ResponsiveTable, { Column } from "common/ResponsiveTable";
@ -15,17 +16,19 @@ interface Props {
export default function CableTable(props: Props) { export default function CableTable(props: Props) {
const { bin, /*cablesChanged*/ } = props; const { bin, /*cablesChanged*/ } = props;
const [{ user }] = useGlobalState();
//const nodeSpacing = 4; //space between the nodes in feet //const nodeSpacing = 4; //space between the nodes in feet
const [cableData, setCableData] = useState(bin.Cables); const [cableData, setCableData] = useState(bin.Cables);
useEffect(() => { useEffect(() => {
let convertedCables: Cable[] = cloneDeep(bin.Cables); let convertedCables: Cable[] = cloneDeep(bin.Cables);
const du = user.distanceUnit();
convertedCables.forEach(cable => { convertedCables.forEach(cable => {
cable.Length = Math.round(distanceConversion(cable.Length) * 100) / 100; cable.Length = Math.round(distanceConversion(cable.Length, du) * 100) / 100;
}); });
setCableData(convertedCables); setCableData(convertedCables);
}, [bin]); }, [bin, user]);
// const table = () => { // const table = () => {
// return ( // return (
@ -116,7 +119,7 @@ export default function CableTable(props: Props) {
render: (row) => <Box padding={2}>{row.Count}</Box> render: (row) => <Box padding={2}>{row.Count}</Box>
}, },
{ {
title: "Length" + (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET ? "(ft)" : "(m)"), title: "Length" + (user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET ? "(ft)" : "(m)"),
render: (row) => <Box padding={2}>{row.Length}</Box> render: (row) => <Box padding={2}>{row.Length}</Box>
}, },
{ {

View file

@ -1,9 +1,9 @@
import { StyleSheet, Text, View } from "@react-pdf/renderer"; import { StyleSheet, Text, View } from "@react-pdf/renderer";
import { pond } from "protobuf-ts/pond"; import { pond } from "protobuf-ts/pond";
import { getDistanceUnit } from "utils";
interface Props { interface Props {
borderColour: string; borderColour: string;
distanceUnit: pond.DistanceUnit;
} }
export default function CableTableHeader(props: Props) { export default function CableTableHeader(props: Props) {
@ -35,7 +35,8 @@ export default function CableTableHeader(props: Props) {
<Text style={styles.cell}>Type</Text> <Text style={styles.cell}>Type</Text>
<Text style={styles.cell}>Qty</Text> <Text style={styles.cell}>Qty</Text>
<Text style={styles.cell}> <Text style={styles.cell}>
Length {getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET ? "(ft)" : "(m)"} Length{" "}
{props.distanceUnit === pond.DistanceUnit.DISTANCE_UNIT_FEET ? "(ft)" : "(m)"}
</Text> </Text>
<Text style={styles.endCell}>Nodes</Text> <Text style={styles.endCell}>Nodes</Text>
</View> </View>

View file

@ -2,10 +2,12 @@ import { StyleSheet, Text, View } from "@react-pdf/renderer";
import { jsonBin } from "common/DataImports/BinCables/BinCableImporter"; import { jsonBin } from "common/DataImports/BinCables/BinCableImporter";
import React from "react"; import React from "react";
import { distanceConversion } from "utils"; import { distanceConversion } from "utils";
import { pond } from "protobuf-ts/pond";
interface Props { interface Props {
bin: jsonBin; bin: jsonBin;
borderColour: string; borderColour: string;
distanceUnit: pond.DistanceUnit;
} }
export default function CableTableRow(props: Props) { export default function CableTableRow(props: Props) {
@ -48,7 +50,9 @@ export default function CableTableRow(props: Props) {
<Text style={styles.cell}>{cable.Orbit === 0 ? "Center" : cable.Orbit}</Text> <Text style={styles.cell}>{cable.Orbit === 0 ? "Center" : cable.Orbit}</Text>
<Text style={styles.cell}>{cable.Type === 2 ? "Moisture" : "Temperature"}</Text> <Text style={styles.cell}>{cable.Type === 2 ? "Moisture" : "Temperature"}</Text>
<Text style={styles.cell}>{cable.Count}</Text> <Text style={styles.cell}>{cable.Count}</Text>
<Text style={styles.cell}>{distanceConversion(cable.Length).toFixed(2)}</Text> <Text style={styles.cell}>
{distanceConversion(cable.Length, props.distanceUnit).toFixed(2)}
</Text>
<Text style={styles.endCell}>{cable.Nodes}</Text> <Text style={styles.endCell}>{cable.Nodes}</Text>
</View> </View>
); );

View file

@ -1,9 +1,9 @@
import { StyleSheet, Text, View } from "@react-pdf/renderer"; import { StyleSheet, Text, View } from "@react-pdf/renderer";
import { pond } from "protobuf-ts/pond"; import { pond } from "protobuf-ts/pond";
import { getDistanceUnit } from "utils";
interface Props { interface Props {
borderColour: string; borderColour: string;
distanceUnit: pond.DistanceUnit;
} }
export default function MountingTableHeader(props: Props) { export default function MountingTableHeader(props: Props) {
@ -43,10 +43,12 @@ export default function MountingTableHeader(props: Props) {
<View style={styles.view}> <View style={styles.view}>
<Text style={styles.orbit}>Orbit</Text> <Text style={styles.orbit}>Orbit</Text>
<Text style={styles.centerDist}> <Text style={styles.centerDist}>
Radius {getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET ? "(ft)" : "(m)"} Radius{" "}
{props.distanceUnit === pond.DistanceUnit.DISTANCE_UNIT_FEET ? "(ft)" : "(m)"}
</Text> </Text>
<Text style={styles.roofDist}> <Text style={styles.roofDist}>
Along Roof {getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET ? "(ft)" : "(m)"} Along Roof{" "}
{props.distanceUnit === pond.DistanceUnit.DISTANCE_UNIT_FEET ? "(ft)" : "(m)"}
</Text> </Text>
<Text style={styles.bracket}>Bracket</Text> <Text style={styles.bracket}>Bracket</Text>
</View> </View>

View file

@ -2,10 +2,12 @@ import { StyleSheet, Text, View } from "@react-pdf/renderer";
import { getBracket, jsonBin } from "common/DataImports/BinCables/BinCableImporter"; import { getBracket, jsonBin } from "common/DataImports/BinCables/BinCableImporter";
import React from "react"; import React from "react";
import { distanceConversion } from "utils"; import { distanceConversion } from "utils";
import { pond } from "protobuf-ts/pond";
interface Props { interface Props {
bin: jsonBin; bin: jsonBin;
borderColour: string; borderColour: string;
distanceUnit: pond.DistanceUnit;
} }
export default function MountingTableRow(props: Props) { export default function MountingTableRow(props: Props) {
@ -65,10 +67,10 @@ export default function MountingTableRow(props: Props) {
key={i}> key={i}>
<Text style={styles.orbit}>{orbit.Orbit === 0 ? "C" : orbit.Orbit}</Text> <Text style={styles.orbit}>{orbit.Orbit === 0 ? "C" : orbit.Orbit}</Text>
<Text style={styles.centerDist}> <Text style={styles.centerDist}>
{distanceConversion(orbit.DistanceFromCenter).toFixed(2)} {distanceConversion(orbit.DistanceFromCenter, props.distanceUnit).toFixed(2)}
</Text> </Text>
<Text style={styles.roofDist}> <Text style={styles.roofDist}>
{distanceConversion(roofDist(orbit.DistanceFromCenter)).toFixed(2)} {distanceConversion(roofDist(orbit.DistanceFromCenter), props.distanceUnit).toFixed(2)}
</Text> </Text>
<Text style={styles.bracket}> <Text style={styles.bracket}>
{bracketType} {bracketType}

View file

@ -1,6 +1,7 @@
import { StyleSheet, Text, View } from "@react-pdf/renderer"; import { StyleSheet, Text, View } from "@react-pdf/renderer";
import { colors } from "@mui/material"; import { colors } from "@mui/material";
import { jsonBin } from "common/DataImports/BinCables/BinCableImporter"; import { jsonBin } from "common/DataImports/BinCables/BinCableImporter";
import { pond } from "protobuf-ts/pond";
import CableTableHeader from "./cableTable/cableTableHeader"; import CableTableHeader from "./cableTable/cableTableHeader";
import CableTableRow from "./cableTable/cableTableRow"; import CableTableRow from "./cableTable/cableTableRow";
import PDFSideView from "./pdfSVG/pdfSideView"; import PDFSideView from "./pdfSVG/pdfSideView";
@ -10,9 +11,11 @@ import MountingTableRow from "./mountingTable/mountingTableRows";
interface Props { interface Props {
bin: jsonBin; bin: jsonBin;
distanceUnit: pond.DistanceUnit;
} }
export default function PdfContent(props: Props) { export default function PdfContent(props: Props) {
const { distanceUnit } = props;
const tableBorderColour = colors.grey[800]; const tableBorderColour = colors.grey[800];
const styles = StyleSheet.create({ const styles = StyleSheet.create({
@ -53,7 +56,7 @@ export default function PdfContent(props: Props) {
</View> </View>
<View style={{ height: 280, flexDirection: "row" }}> <View style={{ height: 280, flexDirection: "row" }}>
<View style={{ width: 260 }}> <View style={{ width: 260 }}>
<PDFSideView bin={props.bin} /> <PDFSideView bin={props.bin} distanceUnit={distanceUnit} />
</View> </View>
<View style={{ width: 260 }}> <View style={{ width: 260 }}>
<View style={{ height: 195 }}> <View style={{ height: 195 }}>
@ -63,8 +66,12 @@ export default function PdfContent(props: Props) {
<Text style={{ fontFamily: "Helvetica-Bold", marginBottom: 5 }}>Install Guide</Text> <Text style={{ fontFamily: "Helvetica-Bold", marginBottom: 5 }}>Install Guide</Text>
<View <View
style={{ borderColor: tableBorderColour, borderWidth: 1, flexDirection: "column" }}> style={{ borderColor: tableBorderColour, borderWidth: 1, flexDirection: "column" }}>
<MountingTableHeader borderColour={tableBorderColour} /> <MountingTableHeader borderColour={tableBorderColour} distanceUnit={distanceUnit} />
<MountingTableRow borderColour={tableBorderColour} bin={props.bin} /> <MountingTableRow
borderColour={tableBorderColour}
bin={props.bin}
distanceUnit={distanceUnit}
/>
</View> </View>
</View> </View>
</View> </View>
@ -73,8 +80,12 @@ export default function PdfContent(props: Props) {
Recommended Cables Recommended Cables
</Text> </Text>
<View style={styles.cableTable}> <View style={styles.cableTable}>
<CableTableHeader borderColour={tableBorderColour} /> <CableTableHeader borderColour={tableBorderColour} distanceUnit={distanceUnit} />
<CableTableRow bin={props.bin} borderColour={tableBorderColour} /> <CableTableRow
bin={props.bin}
borderColour={tableBorderColour}
distanceUnit={distanceUnit}
/>
</View> </View>
</View> </View>
); );

View file

@ -1,11 +1,13 @@
import { colors } from "@mui/material"; import { colors } from "@mui/material";
import { Circle, Line, Path, Svg, Text } from "@react-pdf/renderer"; import { Circle, Line, Path, Svg, Text } from "@react-pdf/renderer";
import { jsonBin } from "common/DataImports/BinCables/BinCableImporter"; import { jsonBin } from "common/DataImports/BinCables/BinCableImporter";
import { pond } from "protobuf-ts/pond";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { distanceConversion } from "utils"; import { distanceConversion } from "utils";
interface Props { interface Props {
bin: jsonBin; bin: jsonBin;
distanceUnit: pond.DistanceUnit;
} }
interface svgPoint { interface svgPoint {
@ -22,7 +24,7 @@ export default function PDFSideView(props: Props) {
const nodeSpacing = 4; //space in feet between the nodes const nodeSpacing = 4; //space in feet between the nodes
const dimensionFontSize = 18; const dimensionFontSize = 18;
const gapSize = svgViewBoxSize * 0.05; const gapSize = svgViewBoxSize * 0.05;
const { bin } = props; const { bin, distanceUnit } = props;
const [scale, setScale] = useState(0); //the scale to multiply the bin dimension by in order to determine how long to draw the line const [scale, setScale] = useState(0); //the scale to multiply the bin dimension by in order to determine how long to draw the line
const [hopperHeight, setHopperHeight] = useState(0); const [hopperHeight, setHopperHeight] = useState(0);
const [roofHeight, setRoofHeight] = useState(0); const [roofHeight, setRoofHeight] = useState(0);
@ -194,7 +196,7 @@ export default function PDFSideView(props: Props) {
"bottomText", "bottomText",
svgViewBoxSize / 2, svgViewBoxSize / 2,
y2, y2,
distanceConversion(bin.Diameter).toFixed(1) distanceConversion(bin.Diameter, distanceUnit).toFixed(1)
) )
); );
@ -231,7 +233,12 @@ export default function PDFSideView(props: Props) {
let y2 = (roofHeight + bin.Sidewall) * scale; let y2 = (roofHeight + bin.Sidewall) * scale;
d.push( d.push(
dimensionText("sidewallText", x2, midpoint, distanceConversion(bin.Sidewall).toFixed(1)) dimensionText(
"sidewallText",
x2,
midpoint,
distanceConversion(bin.Sidewall, distanceUnit).toFixed(1)
)
); );
d.push( d.push(
dimensionPath( dimensionPath(
@ -270,7 +277,7 @@ export default function PDFSideView(props: Props) {
"peakText", "peakText",
xText, xText,
midpoint, midpoint,
distanceConversion(bin.Sidewall + roofHeight).toFixed(1) distanceConversion(bin.Sidewall + roofHeight, distanceUnit).toFixed(1)
) )
); );
d.push( d.push(
@ -313,7 +320,7 @@ export default function PDFSideView(props: Props) {
"totalText", "totalText",
x2, x2,
midpoint, midpoint,
distanceConversion(roofHeight + bin.Sidewall + hopperHeight).toFixed(1) distanceConversion(roofHeight + bin.Sidewall + hopperHeight, distanceUnit).toFixed(1)
) )
); );
d.push( d.push(

View file

@ -44,7 +44,6 @@ import { bestUnit, milliToX } from "common/time/duration";
import { useGlobalState } from "providers"; import { useGlobalState } from "providers";
import { green, red } from "@mui/material/colors"; import { green, red } from "@mui/material/colors";
import { makeStyles } from "@mui/styles"; import { makeStyles } from "@mui/styles";
import { getDistanceUnit } from "utils";
import { GrainOptions } from "grain"; import { GrainOptions } from "grain";
import CompModes from "component/ComponentMode.json"; import CompModes from "component/ComponentMode.json";
import FanPicker from "fans/fanPicker"; import FanPicker from "fans/fanPicker";
@ -177,11 +176,11 @@ export default function ComponentForm(props: Props) {
let width = formComponent.settings.containerDimensions?.widthCm ?? 0; let width = formComponent.settings.containerDimensions?.widthCm ?? 0;
let height = formComponent.settings.containerDimensions?.heightCm ?? 0; let height = formComponent.settings.containerDimensions?.heightCm ?? 0;
if (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS) { if (user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS) {
length = length / 100; length = length / 100;
width = width / 100; width = width / 100;
height = height / 100; height = height / 100;
} else if (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET) { } else if (user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET) {
length = length / 30.48; length = length / 30.48;
width = width / 30.48; width = width / 30.48;
height = height / 30.48; height = height / 30.48;
@ -189,9 +188,9 @@ export default function ComponentForm(props: Props) {
let sensorDistance = formComponent.settings.sensorDistanceCm ?? 0; let sensorDistance = formComponent.settings.sensorDistanceCm ?? 0;
if (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS) { if (user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS) {
sensorDistance = sensorDistance / 100; sensorDistance = sensorDistance / 100;
} else if (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET) { } else if (user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET) {
sensorDistance = sensorDistance / 30.48; sensorDistance = sensorDistance / 30.48;
} }
@ -520,9 +519,9 @@ export default function ComponentForm(props: Props) {
if (!isNaN(Number(event.target.value))) { if (!isNaN(Number(event.target.value))) {
let dimensions = f.component.settings.containerDimensions; let dimensions = f.component.settings.containerDimensions;
let value = Number(event.target.value); let value = Number(event.target.value);
if (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS) { if (user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS) {
value = value * 100; value = value * 100;
} else if (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET) { } else if (user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET) {
value = value * 30.48; value = value * 30.48;
} }
if (dimensions !== undefined && dimensions !== null) { if (dimensions !== undefined && dimensions !== null) {
@ -549,9 +548,9 @@ export default function ComponentForm(props: Props) {
if (!isNaN(Number(event.target.value))) { if (!isNaN(Number(event.target.value))) {
let dimensions = f.component.settings.containerDimensions; let dimensions = f.component.settings.containerDimensions;
let value = Number(event.target.value); let value = Number(event.target.value);
if (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS) { if (user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS) {
value = value * 100; value = value * 100;
} else if (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET) { } else if (user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET) {
value = value * 30.48; value = value * 30.48;
} }
if (dimensions !== undefined && dimensions !== null) { if (dimensions !== undefined && dimensions !== null) {
@ -578,9 +577,9 @@ export default function ComponentForm(props: Props) {
if (!isNaN(Number(event.target.value))) { if (!isNaN(Number(event.target.value))) {
let dimensions = f.component.settings.containerDimensions; let dimensions = f.component.settings.containerDimensions;
let value = Number(event.target.value); let value = Number(event.target.value);
if (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS) { if (user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS) {
value = value * 100; value = value * 100;
} else if (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET) { } else if (user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET) {
value = value * 30.48; value = value * 30.48;
} }
if (dimensions !== undefined && dimensions !== null) { if (dimensions !== undefined && dimensions !== null) {
@ -606,9 +605,9 @@ export default function ComponentForm(props: Props) {
f.sensorDistance = event.target.value; f.sensorDistance = event.target.value;
if (!isNaN(Number(event.target.value))) { if (!isNaN(Number(event.target.value))) {
let value = Number(event.target.value); let value = Number(event.target.value);
if (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS) { if (user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS) {
value = value * 100; value = value * 100;
} else if (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET) { } else if (user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET) {
value = value * 30.48; value = value * 30.48;
} }
f.component.settings.sensorDistanceCm = value; f.component.settings.sensorDistanceCm = value;
@ -1252,7 +1251,7 @@ export default function ComponentForm(props: Props) {
InputProps={{ InputProps={{
endAdornment: ( endAdornment: (
<InputAdornment position="end"> <InputAdornment position="end">
{getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS {user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS
? "m" ? "m"
: "ft"} : "ft"}
</InputAdornment> </InputAdornment>
@ -1276,7 +1275,7 @@ export default function ComponentForm(props: Props) {
InputProps={{ InputProps={{
endAdornment: ( endAdornment: (
<InputAdornment position="end"> <InputAdornment position="end">
{getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS {user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS
? "m" ? "m"
: "ft"} : "ft"}
</InputAdornment> </InputAdornment>
@ -1300,7 +1299,7 @@ export default function ComponentForm(props: Props) {
InputProps={{ InputProps={{
endAdornment: ( endAdornment: (
<InputAdornment position="end"> <InputAdornment position="end">
{getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS {user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS
? "m" ? "m"
: "ft"} : "ft"}
</InputAdornment> </InputAdornment>
@ -1328,7 +1327,7 @@ export default function ComponentForm(props: Props) {
InputProps={{ InputProps={{
endAdornment: ( endAdornment: (
<InputAdornment position="end"> <InputAdornment position="end">
{getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS ? "m" : "ft"} {user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS ? "m" : "ft"}
</InputAdornment> </InputAdornment>
) )
}} }}

View file

@ -34,7 +34,6 @@ import { FeatureCollection, Feature } from "geojson";
import DrawController from "./mapControllers/drawController"; import DrawController from "./mapControllers/drawController";
//import { Geometry } from "geojson"; //import { Geometry } from "geojson";
import Map, { MapRef, Marker, MarkerDragEvent } from "react-map-gl/mapbox"; import Map, { MapRef, Marker, MarkerDragEvent } from "react-map-gl/mapbox";
import { getDistanceUnit } from "utils";
import { MapMouseEvent } from "mapbox-gl"; import { MapMouseEvent } from "mapbox-gl";
import { makeStyles } from "@mui/styles"; import { makeStyles } from "@mui/styles";
import { Result } from "@mapbox/mapbox-gl-geocoder"; import { Result } from "@mapbox/mapbox-gl-geocoder";
@ -499,7 +498,7 @@ export default function MapBase(props: Props) {
lineWidth: 5, lineWidth: 5,
origin: pond.DataOrigin.DATA_ORIGIN_ADAPTIVE, origin: pond.DataOrigin.DATA_ORIGIN_ADAPTIVE,
totalDist: totalDist:
getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS
? (data.totalDistanceKm * 1000).toFixed(2) ? (data.totalDistanceKm * 1000).toFixed(2)
: (data.totalDistanceKm * 3280.8398950131).toFixed(2) : (data.totalDistanceKm * 3280.8398950131).toFixed(2)
}; };

View file

@ -7,8 +7,6 @@ import { Bin, BinYard, Field, User } from "models";
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 } 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
numerical: boolean; //whether to use a numerical or text sort numerical: boolean; //whether to use a numerical or text sort
@ -62,7 +60,10 @@ const binColumns = (user?: User): Column<any>[] => {
render: row => { render: row => {
let d = row.settings.specs?.heightCm; let d = row.settings.specs?.heightCm;
if (d) { if (d) {
if (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS) { if (
(user?.distanceUnit() ?? pond.DistanceUnit.DISTANCE_UNIT_FEET) ===
pond.DistanceUnit.DISTANCE_UNIT_METERS
) {
return (d / 100).toFixed(2) + " m"; return (d / 100).toFixed(2) + " m";
} else { } else {
return (d / 30.48).toFixed(2) + " ft"; return (d / 30.48).toFixed(2) + " ft";
@ -76,7 +77,10 @@ const binColumns = (user?: User): Column<any>[] => {
render: row => { render: row => {
let d = row.settings.specs?.diameterCm; let d = row.settings.specs?.diameterCm;
if (d) { if (d) {
if (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS) { if (
(user?.distanceUnit() ?? pond.DistanceUnit.DISTANCE_UNIT_FEET) ===
pond.DistanceUnit.DISTANCE_UNIT_METERS
) {
return (d / 100).toFixed(2) + " m"; return (d / 100).toFixed(2) + " m";
} else { } else {
return (d / 30.48).toFixed(2) + " ft"; return (d / 30.48).toFixed(2) + " ft";
@ -141,6 +145,89 @@ const binColumns = (user?: User): Column<any>[] => {
] as Column<Bin>[]; ] as Column<Bin>[];
}; };
const grainBagColumns = (user?: User): Column<GrainBag>[] => {
const distanceUnit =
user?.distanceUnit() ?? pond.DistanceUnit.DISTANCE_UNIT_FEET;
return [
{
title: "Name",
render: row => {
if (row.title) {
return (<div>{row.title.toString()}</div>);
}
}
},
{
title: "Length",
render: row => {
if (row.settings.length) {
if (distanceUnit === pond.DistanceUnit.DISTANCE_UNIT_METERS) {
return row.settings.length.toFixed(2) + " m";
} else {
return (row.settings.length * 3.281).toFixed(2) + " ft";
}
}
}
},
{
title: "Diameter",
render: row => {
if (row.settings.diameter) {
if (distanceUnit === pond.DistanceUnit.DISTANCE_UNIT_METERS) {
return row.settings.diameter.toFixed(2) + " m";
} else {
return (row.settings.diameter * 3.281).toFixed(2) + " ft";
}
}
}
},
{
title: "Grain",
render: row => {
if (row.settings.supportedGrain) {
return GrainDescriber(row.settings.supportedGrain).name;
}
}
},
{
title: "Custom Grain",
render: row => {
return row.settings.customGrain;
}
},
{
title: "Grain Variant",
render: row => {
return row.settings.grainSubtype;
}
},
{
title: "Capacity",
render: row => {
return row.settings.bushelCapacity + " bu";
}
},
{
title: "Bushels",
render: row => {
return row.settings.currentBushels + " bu";
}
},
{
title: "Fill Date",
render: row => {
return row.settings.fillDate;
}
},
{
title: "Initial Moisture",
render: row => {
return row.settings.initialMoisture + "%";
}
}
] as Column<GrainBag>[];
};
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],
[ [
@ -403,84 +490,8 @@ export const ObjectExtensions: Map<pond.ObjectType, ObjectExtension> = new Map([
name: "Grainbag", name: "Grainbag",
inventoryGroup: "grain", inventoryGroup: "grain",
isTransactionObject: true, isTransactionObject: true,
tableColumns: [ tableColumns: grainBagColumns(),
{ getTableColumns: (user?: User) => grainBagColumns(user),
title: "Name",
render: row => {
if (row.title) {
return (<div>{row.title.toString()}</div>);
}
}
},
{
title: "Length",
render: row => {
if (row.settings.length) {
if (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS) {
return row.settings.length.toFixed(2) + " m";
} else {
return (row.settings.length * 3.281).toFixed(2) + " ft";
}
}
}
},
{
title: "Diameter",
render: row => {
if (row.settings.diameter) {
if (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS) {
return row.settings.diameter.toFixed(2) + " m";
} else {
return (row.settings.diameter * 3.281).toFixed(2) + " ft";
}
}
}
},
{
title: "Grain",
render: row => {
if (row.settings.supportedGrain) {
return GrainDescriber(row.settings.supportedGrain).name;
}
}
},
{
title: "Custom Grain",
render: row => {
return row.settings.customGrain;
}
},
{
title: "Grain Variant",
render: row => {
return row.settings.grainSubtype;
}
},
{
title: "Capacity",
render: row => {
return row.settings.bushelCapacity + " bu";
}
},
{
title: "Bushels",
render: row => {
return row.settings.currentBushels + " bu";
}
},
{
title: "Fill Date",
render: row => {
return row.settings.fillDate;
}
},
{
title: "Initial Moisture",
render: row => {
return row.settings.initialMoisture + "%";
}
}
] as Column<GrainBag>[],
tableSort: new Map([ tableSort: new Map([
["Name", { order: "name", numerical: false }], ["Name", { order: "name", numerical: false }],
["Length", { order: "length", numerical: true }], ["Length", { order: "length", numerical: true }],

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 } from "utils"; import { fahrenheitToCelsius } from "utils";
interface Props { interface Props {
selectedBins: pond.Bin[]; selectedBins: pond.Bin[];
@ -32,10 +32,10 @@ export default function BulkBinSettings(props: Props) {
const [lowTemp, setLowTemp] = useState<number | undefined>(); const [lowTemp, setLowTemp] = useState<number | undefined>();
const convertedDistance = (enteredDistance: number) => { const convertedDistance = (enteredDistance: number) => {
if (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS) { if (user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS) {
return enteredDistance * 100; return enteredDistance * 100;
} }
if (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET) { if (user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET) {
return enteredDistance * 30.48; return enteredDistance * 30.48;
} }
return enteredDistance; return enteredDistance;
@ -168,7 +168,7 @@ export default function BulkBinSettings(props: Props) {
InputProps={{ InputProps={{
endAdornment: ( endAdornment: (
<InputAdornment position="end"> <InputAdornment position="end">
{getDistanceUnit() !== pond.DistanceUnit.DISTANCE_UNIT_FEET ? "m" : "ft"} {user.distanceUnit() !== pond.DistanceUnit.DISTANCE_UNIT_FEET ? "m" : "ft"}
</InputAdornment> </InputAdornment>
) )
}} }}
@ -186,7 +186,7 @@ export default function BulkBinSettings(props: Props) {
InputProps={{ InputProps={{
endAdornment: ( endAdornment: (
<InputAdornment position="end"> <InputAdornment position="end">
{getDistanceUnit() !== pond.DistanceUnit.DISTANCE_UNIT_FEET ? "m" : "ft"} {user.distanceUnit() !== pond.DistanceUnit.DISTANCE_UNIT_FEET ? "m" : "ft"}
</InputAdornment> </InputAdornment>
) )
}} }}

View file

@ -5,7 +5,6 @@ import { GrainBag } from "models/GrainBag";
import { pond } from "protobuf-ts/pond"; import { pond } from "protobuf-ts/pond";
import { useGlobalState, useGrainBagAPI, useSnackbar } from "providers"; import { useGlobalState, useGrainBagAPI, useSnackbar } from "providers";
import React, { useState } from "react"; import React, { useState } from "react";
import { getDistanceUnit } from "utils";
interface Props { interface Props {
selectedBags: GrainBag[]; selectedBags: GrainBag[];
@ -28,10 +27,10 @@ export default function BulkGrainBagSettings(props: Props) {
const [bushels, setBushels] = useState<number | undefined>(); const [bushels, setBushels] = useState<number | undefined>();
const [fillDate, setFillDate] = useState<string | undefined>(); const [fillDate, setFillDate] = useState<string | undefined>();
const [initialMoisture, setInitialMoisture] = useState<number | undefined>(); const [initialMoisture, setInitialMoisture] = useState<number | undefined>();
const [{as}] = useGlobalState(); const [{ as, user }] = useGlobalState();
const convertedDistance = (enteredDistance: number) => { const convertedDistance = (enteredDistance: number) => {
if (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET) { if (user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET) {
return enteredDistance / 3.281; return enteredDistance / 3.281;
} }
return enteredDistance; return enteredDistance;

View file

@ -19,7 +19,7 @@ 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, roundTo } from "utils"; import { roundTo } from "utils";
import { extract } from "utils/types"; import { extract } from "utils/types";
interface Enumeration { interface Enumeration {
@ -440,7 +440,8 @@ export class MeasurementDescriber {
this.details.max = 100000; this.details.max = 100000;
break; break;
case quack.MeasurementType.MEASUREMENT_TYPE_DISTANCE_CM: case quack.MeasurementType.MEASUREMENT_TYPE_DISTANCE_CM:
let distanceUnit = getDistanceUnit(); let distanceUnit =
user?.distanceUnit() ?? pond.DistanceUnit.DISTANCE_UNIT_FEET;
this.details.label = "Distance"; this.details.label = "Distance";
this.details.unit = "cm"; this.details.unit = "cm";
if (distanceUnit === pond.DistanceUnit.DISTANCE_UNIT_FEET) { if (distanceUnit === pond.DistanceUnit.DISTANCE_UNIT_FEET) {
@ -454,7 +455,8 @@ export class MeasurementDescriber {
this.details.max = 100000; this.details.max = 100000;
break; break;
case quack.MeasurementType.MEASUREMENT_TYPE_SPEED: case quack.MeasurementType.MEASUREMENT_TYPE_SPEED:
let speedUnit = getDistanceUnit() let speedUnit =
user?.distanceUnit() ?? pond.DistanceUnit.DISTANCE_UNIT_FEET;
this.details.label = "Speed"; this.details.label = "Speed";
this.details.unit = speedUnit === pond.DistanceUnit.DISTANCE_UNIT_METERS ? "m/s" : "ft/m"; //yes this is meters per second and feet per minute this.details.unit = speedUnit === pond.DistanceUnit.DISTANCE_UNIT_METERS ? "m/s" : "ft/m"; //yes this is meters per second and feet per minute
this.details.colour = green["500"]; this.details.colour = green["500"];

View file

@ -46,6 +46,7 @@ export function setPressureUnit(unit: pond.PressureUnit) {
); );
} }
// function is deprecated, use User.distanceUnit() instead
export function getDistanceUnit(): pond.DistanceUnit { export function getDistanceUnit(): pond.DistanceUnit {
return localStorage.getItem("distance") === "m" return localStorage.getItem("distance") === "m"
? pond.DistanceUnit.DISTANCE_UNIT_METERS ? pond.DistanceUnit.DISTANCE_UNIT_METERS
@ -86,10 +87,10 @@ export function setGrainUnit(unit: pond.GrainUnit) {
// localStorage.setItem("grainUnit", unit === pond.GrainUnit.GRAIN_UNIT_WEIGHT ? "mT" : "bu"); // localStorage.setItem("grainUnit", unit === pond.GrainUnit.GRAIN_UNIT_WEIGHT ? "mT" : "bu");
} }
export const distanceConversion = (val: number) => { export const distanceConversion = (val: number, distanceUnit: pond.DistanceUnit) => {
let converted = val; let converted = val;
if (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS) { if (distanceUnit === pond.DistanceUnit.DISTANCE_UNIT_METERS) {
converted = val / 3.281; converted = val / 3.281;
} }
return converted; return converted;