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:
parent
c6bb7aa24a
commit
dc54f99abd
20 changed files with 273 additions and 199 deletions
|
|
@ -4,7 +4,7 @@ import SearchSelect, { Option } from "common/SearchSelect";
|
|||
import { useMobile } from "hooks";
|
||||
import { pond } from "protobuf-ts/pond";
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { getDistanceUnit } from "utils";
|
||||
import { useGlobalState } from "providers";
|
||||
|
||||
interface Props {
|
||||
optionsChanged: (binOptions: jsonBin[]) => void;
|
||||
|
|
@ -13,6 +13,7 @@ interface Props {
|
|||
|
||||
export default function BinSelector(props: Props) {
|
||||
const { optionsChanged, vertical } = props;
|
||||
const [{user}] = useGlobalState();
|
||||
const isMobile = useMobile();
|
||||
const [manufacturerOptions, SetManufacturerOptions] = useState<Option[]>([]);
|
||||
const [manufacturer, SetManufacturer] = useState<Option | null>(null);
|
||||
|
|
@ -126,7 +127,7 @@ export default function BinSelector(props: Props) {
|
|||
}}
|
||||
label={
|
||||
"Minimum Diameter " +
|
||||
(getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET ? "(ft)" : "(m)")
|
||||
(user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET ? "(ft)" : "(m)")
|
||||
}
|
||||
/>
|
||||
</Grid>
|
||||
|
|
@ -143,7 +144,7 @@ export default function BinSelector(props: Props) {
|
|||
}}
|
||||
label={
|
||||
"Maximum Diameter " +
|
||||
(getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET ? "(ft)" : "(m)")
|
||||
(user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET ? "(ft)" : "(m)")
|
||||
}
|
||||
/>
|
||||
</Grid>
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ import { pond } from "protobuf-ts/pond";
|
|||
import { useBinAPI, useBinYardAPI, useGlobalState, useLibraCartProxyAPI } from "providers";
|
||||
import React, { useCallback, useEffect, useState } from "react";
|
||||
// import { useHistory } from "react-router";
|
||||
import { getDistanceUnit, or, getGrainUnit } from "utils";
|
||||
import { or, getGrainUnit } from "utils";
|
||||
import { makeStyles } from "@mui/styles";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import BinSelector from "./BinSelector";
|
||||
|
|
@ -269,7 +269,7 @@ export default function BinSettings(props: Props) {
|
|||
let sidewallHeight = "";
|
||||
let hopperHeight = "";
|
||||
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);
|
||||
d = (initForm.specs.diameterCm * 0.0328).toFixed(2);
|
||||
if (initForm.specs.advancedDimensions) {
|
||||
|
|
@ -350,7 +350,7 @@ export default function BinSettings(props: Props) {
|
|||
setMoistureTargetDeviation(initForm.inventory?.moistureTargetDeviation.toString() ?? "0");
|
||||
setAutoFillThreshold(initForm.inventory?.autoThreshold ?? 5)
|
||||
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
|
||||
}
|
||||
setLidarDropDistance(dropDistance)
|
||||
|
|
@ -475,7 +475,7 @@ export default function BinSettings(props: Props) {
|
|||
if (form.inventory) {
|
||||
form.inventory.inventoryControl = inventoryControl
|
||||
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){
|
||||
form.inventory.customGrain = undefined
|
||||
}else{
|
||||
|
|
@ -529,7 +529,7 @@ export default function BinSettings(props: Props) {
|
|||
form.inventory.inventoryControl = inventoryControl
|
||||
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
|
||||
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){
|
||||
form.inventory.customGrain = undefined
|
||||
}else{
|
||||
|
|
@ -1099,7 +1099,7 @@ export default function BinSettings(props: Props) {
|
|||
InputProps={{
|
||||
endAdornment: (
|
||||
<InputAdornment position="end">
|
||||
{getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET ? "ft" : "cm"}
|
||||
{user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET ? "ft" : "cm"}
|
||||
</InputAdornment>
|
||||
)
|
||||
}}
|
||||
|
|
@ -1435,7 +1435,7 @@ export default function BinSettings(props: Props) {
|
|||
let sH = sidewallHeight;
|
||||
let hH = hopperHeight ?? 0;
|
||||
let d = diameter;
|
||||
if (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS) {
|
||||
if (user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS) {
|
||||
tcH = tcH * 3.281;
|
||||
sH = sH * 3.281;
|
||||
hH = hH * 3.281;
|
||||
|
|
@ -1463,7 +1463,7 @@ export default function BinSettings(props: Props) {
|
|||
let hopperHeight = formExtension.hopperHeight;
|
||||
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);
|
||||
// heightM = (Number(heightM) * 3.28084).toFixed(2);
|
||||
// }
|
||||
|
|
@ -1552,7 +1552,7 @@ export default function BinSettings(props: Props) {
|
|||
let d = diameter;
|
||||
let valueM = value;
|
||||
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);
|
||||
dM = (Number(d) * 0.3048).toFixed(2);
|
||||
}
|
||||
|
|
@ -1577,7 +1577,7 @@ export default function BinSettings(props: Props) {
|
|||
InputProps={{
|
||||
endAdornment: (
|
||||
<InputAdornment position="end">
|
||||
{getDistanceUnit() !== pond.DistanceUnit.DISTANCE_UNIT_FEET ? "m" : "ft"}
|
||||
{user.distanceUnit() !== pond.DistanceUnit.DISTANCE_UNIT_FEET ? "m" : "ft"}
|
||||
</InputAdornment>
|
||||
)
|
||||
}}
|
||||
|
|
@ -1637,7 +1637,7 @@ export default function BinSettings(props: Props) {
|
|||
let value = event?.target.value;
|
||||
let valueM = value;
|
||||
setModelID(0);
|
||||
if (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET) {
|
||||
if (user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET) {
|
||||
valueM = (Number(value) * 0.3048).toFixed(2);
|
||||
}
|
||||
let coneCM =
|
||||
|
|
@ -1674,7 +1674,7 @@ export default function BinSettings(props: Props) {
|
|||
|
||||
//need to get the total height in cm
|
||||
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
|
||||
}else{
|
||||
totalHeightCM = totalHeightCM * 100 //convert from m to cm
|
||||
|
|
@ -1698,7 +1698,7 @@ export default function BinSettings(props: Props) {
|
|||
InputProps={{
|
||||
endAdornment: (
|
||||
<InputAdornment position="end">
|
||||
{getDistanceUnit() !== pond.DistanceUnit.DISTANCE_UNIT_FEET
|
||||
{user.distanceUnit() !== pond.DistanceUnit.DISTANCE_UNIT_FEET
|
||||
? "m"
|
||||
: "ft"}
|
||||
</InputAdornment>
|
||||
|
|
@ -1725,7 +1725,7 @@ export default function BinSettings(props: Props) {
|
|||
//calculate the new cone height for the roof angle
|
||||
let coneCM = TriangleOppositeLength(d / 2, angle ?? 0);
|
||||
let newConeHeight =
|
||||
getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET
|
||||
user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET
|
||||
? (coneCM / 30.48).toFixed(2)
|
||||
: (coneCM / 100).toFixed(2);
|
||||
|
||||
|
|
@ -1749,7 +1749,7 @@ export default function BinSettings(props: Props) {
|
|||
|
||||
//need to get the total height in cm
|
||||
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
|
||||
}else{
|
||||
totalHeightCM = totalHeightCM * 100 //convert from m to cm
|
||||
|
|
@ -1786,7 +1786,7 @@ export default function BinSettings(props: Props) {
|
|||
onChange={event => {
|
||||
let value = event?.target.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);
|
||||
}
|
||||
let ext = cloneDeep(formExtension);
|
||||
|
|
@ -1811,7 +1811,7 @@ export default function BinSettings(props: Props) {
|
|||
|
||||
//need to get the total height in cm
|
||||
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
|
||||
}else{
|
||||
totalHeightCM = totalHeightCM * 100 //convert from m to cm
|
||||
|
|
@ -1838,7 +1838,7 @@ export default function BinSettings(props: Props) {
|
|||
InputProps={{
|
||||
endAdornment: (
|
||||
<InputAdornment position="end">
|
||||
{getDistanceUnit() !== pond.DistanceUnit.DISTANCE_UNIT_FEET
|
||||
{user.distanceUnit() !== pond.DistanceUnit.DISTANCE_UNIT_FEET
|
||||
? "m"
|
||||
: "ft"}
|
||||
</InputAdornment>
|
||||
|
|
@ -1868,7 +1868,7 @@ export default function BinSettings(props: Props) {
|
|||
let coneCM = TriangleOppositeLength(d / 2, angle ?? 0);
|
||||
|
||||
let newHopperHeight =
|
||||
getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET
|
||||
user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET
|
||||
? (coneCM / 30.48).toFixed(2)
|
||||
: (coneCM / 100).toFixed(2);
|
||||
|
||||
|
|
@ -1926,7 +1926,7 @@ export default function BinSettings(props: Props) {
|
|||
onChange={event => {
|
||||
let value = event?.target.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);
|
||||
}
|
||||
|
||||
|
|
@ -1982,7 +1982,7 @@ export default function BinSettings(props: Props) {
|
|||
InputProps={{
|
||||
endAdornment: (
|
||||
<InputAdornment position="end">
|
||||
{getDistanceUnit() !== pond.DistanceUnit.DISTANCE_UNIT_FEET
|
||||
{user.distanceUnit() !== pond.DistanceUnit.DISTANCE_UNIT_FEET
|
||||
? "m"
|
||||
: "ft"}
|
||||
</InputAdornment>
|
||||
|
|
@ -2009,7 +2009,7 @@ export default function BinSettings(props: Props) {
|
|||
let h = height;
|
||||
let valueM = value;
|
||||
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);
|
||||
hM = (Number(h) * 0.3048).toFixed(2);
|
||||
}
|
||||
|
|
@ -2063,7 +2063,7 @@ export default function BinSettings(props: Props) {
|
|||
InputProps={{
|
||||
endAdornment: (
|
||||
<InputAdornment position="end">
|
||||
{getDistanceUnit() !== pond.DistanceUnit.DISTANCE_UNIT_FEET ? "m" : "ft"}
|
||||
{user.distanceUnit() !== pond.DistanceUnit.DISTANCE_UNIT_FEET ? "m" : "ft"}
|
||||
</InputAdornment>
|
||||
)
|
||||
}}
|
||||
|
|
@ -2253,7 +2253,7 @@ export default function BinSettings(props: Props) {
|
|||
let userHopperHeight = hopperHeight;
|
||||
let userDiameter = jsonBin.Diameter;
|
||||
//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;
|
||||
userDiameter = userDiameter / 3.281;
|
||||
userTopCone = userTopCone / 3.281;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue