From 1fbc817abe599d99e3b499e9d76ce2f5e53b78ae Mon Sep 17 00:00:00 2001 From: csawatzky Date: Fri, 29 Aug 2025 12:36:45 -0600 Subject: [PATCH] put the first components into the field page --- src/field/FieldActions.tsx | 2 + src/field/FieldList.tsx | 21 +++++-- src/navigation/Router.tsx | 18 +++++- src/pages/Field.tsx | 123 +++++++++++++++++++++++++++++++++++++ 4 files changed, 159 insertions(+), 5 deletions(-) create mode 100644 src/pages/Field.tsx diff --git a/src/field/FieldActions.tsx b/src/field/FieldActions.tsx index fbaf090..7e0cb44 100644 --- a/src/field/FieldActions.tsx +++ b/src/field/FieldActions.tsx @@ -63,6 +63,8 @@ export default function FieldActions(props: Props) { removeSelf: false }); + console.log(permissions) + const groupMenu = () => { const canShare = permissions.includes(pond.Permission.PERMISSION_SHARE); const canManageUsers = permissions.includes(pond.Permission.PERMISSION_USERS); diff --git a/src/field/FieldList.tsx b/src/field/FieldList.tsx index 6b074f8..36d0de7 100644 --- a/src/field/FieldList.tsx +++ b/src/field/FieldList.tsx @@ -30,9 +30,11 @@ import ResponsiveTable, { Column } from "common/ResponsiveTable"; import FieldMinimap from "./Fieldminimap"; import FieldActions from "./FieldActions"; import FieldSettings from "./FieldSettings"; -import { ExpandMore, Settings } from "@mui/icons-material"; +import { ArrowForward, ExpandMore, Settings } from "@mui/icons-material"; import { cloneDeep } from "lodash"; import ShareAllFields from "./ShareAllFields"; +import EventBlocker from "common/EventBlocker"; +import { useNavigate } from "react-router-dom"; interface TabPanelProps { children?: React.ReactNode; @@ -57,6 +59,7 @@ export default function FieldList() { const [selectedField, setSelectedField] = useState() const [openFieldSettings, setOpenFieldSettings] = useState(false) const [shareOpen, setShareOpen] = useState(false) + const navigate = useNavigate(); const handleChange = (event: React.ChangeEvent<{}>, newValue: number) => { setTabValue(newValue); @@ -117,16 +120,22 @@ export default function FieldList() { return totalAcres; }; + const goTo = (field: Field) => { + let path = field.key(); + navigate(path, { state: {field: field, permissions: field.permissions} }); + } + const fieldActions = (field: Field) => { return ( - + { setSelectedField(field) setOpenFieldSettings(true) }}> {}}/> - + {isMobile && {goTo(field)}}>} + ) } @@ -171,6 +180,9 @@ const columns: Column[] = [ columns={columns} rows={fields} + onRowClick={(row) => { + !isMobile && goTo(row) + }} setPage={(newPage)=>{ setPage(newPage) }} @@ -224,7 +236,7 @@ const columns: Column[] = [ - + @@ -232,6 +244,7 @@ const columns: Column[] = [ {row.grainName()} {row.acres()} Acres + diff --git a/src/navigation/Router.tsx b/src/navigation/Router.tsx index afe12c5..c54c291 100644 --- a/src/navigation/Router.tsx +++ b/src/navigation/Router.tsx @@ -47,6 +47,7 @@ const Contract = lazy(() => import("pages/Contract")); const JohnDeere = lazy(() => import("pages/JohnDeere")); const CNHi = lazy(() => import("pages/CNHi")); const LibraCart = lazy(() => import("pages/LibraCart")); +const FieldPage = lazy(()=>import("pages/Field")); export const appendToUrl = (appendage: number | string) => { const basePath = location.pathname.replace(/\/$/, ""); @@ -70,6 +71,7 @@ export default function Router() { } /> } /> } /> + } /> ) } @@ -284,6 +286,21 @@ export default function Router() { ); }; + const FieldsRoute = () => { + return ( + + } + /> + } + /> + + ); + } + if (isLoading) return null; // if (!isAuthenticated) { // loginWithRedirect() @@ -325,7 +342,6 @@ export default function Router() { {user.hasFeature("admin") && } /> } - } /> } /> {user.hasFeature("admin") && ( } /> diff --git a/src/pages/Field.tsx b/src/pages/Field.tsx new file mode 100644 index 0000000..9302a3b --- /dev/null +++ b/src/pages/Field.tsx @@ -0,0 +1,123 @@ +import { Field, HarvestPlan } from "models"; +import { useGlobalState } from "providers"; +import { useEffect, useState } from "react"; +import { useLocation } from "react-router-dom"; +import PageContainer from "./PageContainer"; +import { useMobile } from "hooks"; +import { Box, Grid2, IconButton } from "@mui/material"; +import FieldActions from "field/FieldActions"; +import { Settings } from "@mui/icons-material"; +import { pond } from "protobuf-ts/pond"; +import FieldMinimap from "field/Fieldminimap"; +import Weather from "weather/weather"; +import TaskViewer from "tasks/TaskViewer"; +import HarvestPlanDisplay from "harvestPlan/HarvestPlanDisplay"; + +export default function FieldPage() { + const { state } = useLocation(); + //const [{ as }] = useGlobalState() + const [field, setField] = useState(state?.field ? Field.create(state.field) : Field.create()) + const [permissions, setPermissions] = useState(state?.permissions ? state.permissions : []) + const isMobile = useMobile() + const [openFieldSettings, setOpenFieldSettings] = useState(false) + const [planLoading, setPlanLoading] = useState(false) + const [hPlan, setHPlan] = useState(HarvestPlan.create()); + + const loadField = () => { + + } + + useEffect(()=>{ + if(state.field){ + let field = Field.create(state.field) + setField(field) + setPermissions(state.permissions) + } + },[state.field]) + + const fieldActions = () => { + return ( + + { + setOpenFieldSettings(true) + }}> + {}}/> + + ) + } + + const map = () => { + return ( + + + + ) + } + + const weather = () => { + return () + } + + const harvestPlans = () => { + console.log(permissions) + return ( + { + if (updatedPlan) { + setHPlan(updatedPlan); + } + }} + />) + } + + const tasks = () => { + let taskLoadKeys: string[] = []; + if (!planLoading) { + field.key() !== "" && taskLoadKeys.push(field.key()); + //hPlan.key() !== "" && taskLoadKeys.push(hPlan.key()); + } + return () + } + + const desktopView = () => { + return ( + + + {map()} + + + {weather()} + + + {tasks()} + + + {harvestPlans()} + + + ) + } + + const mobileView = () => { + return ( + Mobile will just be the drawer view + ) + } + + const fieldSettings = () => { + + } + + return ( + + {fieldActions()} + {isMobile ? mobileView() : desktopView()} + + ) +} \ No newline at end of file