replaced uses of getGrainUnit to the users grainUnit function to pull form logged in users settings rather than local storage

This commit is contained in:
csawatzky 2026-03-26 12:47:16 -06:00
parent dc54f99abd
commit cabc0146ed
22 changed files with 146 additions and 250 deletions

View file

@ -6,7 +6,6 @@ import moment, { Moment } from "moment";
import { pond } from "protobuf-ts/pond";
import { useGlobalState, useGrainBagAPI, useSnackbar } from "providers";
import { useEffect, useState } from "react";
import { getGrainUnit } from "utils";
interface Props {
grainBag: GrainBag;
@ -21,7 +20,7 @@ export default function GrainBagInventoryGraph(props: Props) {
const [data, setData] = useState<BarData[]>([]);
const [loadingData, setLoadingData] = useState<boolean>(false);
const { openSnack } = useSnackbar();
const [{as}] = useGlobalState();
const [{as, user}] = useGlobalState();
useEffect(() => {
if (grainBag.key() && !loadingData) {
@ -36,12 +35,12 @@ export default function GrainBagInventoryGraph(props: Props) {
//let time = hist.timestamp;
let val = hist.object.grainBagSettings.currentBushels ?? 0;
if (
getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE &&
user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE &&
grainBag.bushelsPerTonne() > 1
) {
val = Math.round((val / grainBag.bushelsPerTonne()) * 100) / 100;
}
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && grainBag.bushelsPerTonne() > 1){
if(user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && grainBag.bushelsPerTonne() > 1){
val = Math.round((val / (grainBag.bushelsPerTonne() * 0.907)) * 100) / 100;
}
if (val !== lastBushels) {
@ -55,10 +54,10 @@ export default function GrainBagInventoryGraph(props: Props) {
});
if (barData.length === 0) {
let val = grainBag.bushels()
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE && grainBag.bushelsPerTonne() > 1){
if(user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE && grainBag.bushelsPerTonne() > 1){
val = grainBag.bushels() / grainBag.bushelsPerTonne()
}
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && grainBag.bushelsPerTonne() > 1){
if(user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && grainBag.bushelsPerTonne() > 1){
val = grainBag.bushels() / (grainBag.bushelsPerTonne() * 0.907)
}
barData.push({
@ -79,10 +78,10 @@ export default function GrainBagInventoryGraph(props: Props) {
const maxYAxis = () => {
let val = grainBag.capacity()
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE){
if(user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE){
val = Math.round((val / grainBag.bushelsPerTonne()) * 100) / 100;
}
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && grainBag.bushelsPerTonne() > 1){
if(user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && grainBag.bushelsPerTonne() > 1){
val = Math.round((val / (grainBag.bushelsPerTonne() * 0.907)) * 100) / 100;
}
return val

View file

@ -22,7 +22,6 @@ import { pond } from "protobuf-ts/pond";
import { useGlobalState, useGrainBagAPI, useSnackbar } from "providers";
import React, { useEffect, useState } from "react";
import { useNavigate } from "react-router-dom";
import { getGrainUnit } from "utils";
const useStyles = makeStyles((theme: Theme) => {
return ({
@ -84,9 +83,9 @@ export default function GrainBagSettings(props: Props) {
: grainBag.settings.length
);
let grainVal = grainBag.bushels();
if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE) {
if (user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE) {
grainVal = grainBag.bushels() / grainBag.bushelsPerTonne();
}else if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON) {
}else if (user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TON) {
grainVal = grainBag.bushels() / (grainBag.bushelsPerTonne() * 0.907)
}
setGrainFill(grainVal.toFixed(2));
@ -120,7 +119,7 @@ export default function GrainBagSettings(props: Props) {
const submit = () => {
//if a bag was passed in do an update
let tonneConversion = bushelConversion
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON){
if(user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TON){
tonneConversion = bushelConversion / 0.907
}
if (grainBag) {
@ -255,9 +254,9 @@ export default function GrainBagSettings(props: Props) {
const grainUnitDisplay = () => {
if(bushelConversion > 1){
if(getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE){
if(user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE){
return "mT"
}else if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON){
}else if (user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TON){
return "t"
}
}else{
@ -422,7 +421,7 @@ export default function GrainBagSettings(props: Props) {
value={grainFill}
onChange={e => {
let bushelVal = +e.target.value;
if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE || getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON) {
if (user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE || user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TON) {
//convert the number as a weight into the bushel value, no changing or conversions necessary
// since these are both user entered fields and should be the same unit (ton or tonne)
bushelVal = +e.target.value * (bushelConversion > 0 ? bushelConversion : 1);

View file

@ -19,9 +19,9 @@ import moment from "moment";
import { pond } from "protobuf-ts/pond";
import { useEffect, useState } from "react";
import { getThemeType } from "theme";
import { getGrainUnit } from "utils";
import GrainBagSVG from "./grainBagSVG";
import { makeStyles } from "@mui/styles";
import { useGlobalState } from "providers";
interface Props {
grainBag: GrainBag;
@ -68,6 +68,7 @@ export default function GrainBagVisualizer(props: Props) {
const [grainDiff, setGrainDiff] = useState<number | undefined>();
const theme = useTheme();
const [openTransaction, setOpenTransaction] = useState(false);
const [{ user }] = useGlobalState();
useEffect(() => {
setFillLevel((grainBag.bushels() / grainBag.capacity()) * 100);
@ -83,13 +84,13 @@ export default function GrainBagVisualizer(props: Props) {
const grainOverlay = () => {
let displayPending = pendingGrainAmount;
let displayDiff = grainDiff;
if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE && grainBag.bushelsPerTonne() > 1) {
if (user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE && grainBag.bushelsPerTonne() > 1) {
if (displayPending && displayDiff) {
displayPending = Math.round((displayPending / grainBag.bushelsPerTonne()) * 100) / 100;
displayDiff = Math.round((displayDiff / grainBag.bushelsPerTonne()) * 100) / 100;
}
}
if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && grainBag.bushelsPerTonne() > 1) {
if (user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && grainBag.bushelsPerTonne() > 1) {
if (displayPending && displayDiff) {
displayPending = Math.round((displayPending / (grainBag.bushelsPerTonne() * 0.907)) * 100) / 100;
displayDiff = Math.round((displayDiff / (grainBag.bushelsPerTonne()* 0.907)) * 100) / 100;
@ -148,7 +149,7 @@ export default function GrainBagVisualizer(props: Props) {
};
const grainAmountDisplay = () => {
if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE && grainBag.bushelsPerTonne() > 1) {
if (user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TONNE && grainBag.bushelsPerTonne() > 1) {
return (
<div style={{ display: "flex", flexDirection: "row" }}>
<Typography variant="body2" style={{ fontWeight: "bold", marginRight: "4px" }}>
@ -157,7 +158,7 @@ export default function GrainBagVisualizer(props: Props) {
<Typography variant="body2">({grainBag.fillPercent()}%)</Typography>
</div>
);
} else if (getGrainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && grainBag.bushelsPerTonne() > 1) {
} else if (user.grainUnit() === pond.GrainUnit.GRAIN_UNIT_TON && grainBag.bushelsPerTonne() > 1) {
return (
<div style={{ display: "flex", flexDirection: "row" }}>
<Typography variant="body2" style={{ fontWeight: "bold", marginRight: "4px" }}>