From 5f13300ba6261d49818947bb4ccfc9fb2face9c4 Mon Sep 17 00:00:00 2001 From: Saiyida Noor Date: Wed, 6 Aug 2025 17:08:58 +0000 Subject: [PATCH 01/30] minor updates --- src/device/presets/devicePresetCard.tsx | 108 ++++++++--------- src/pages/LibraCart.tsx | 80 ++++++------- src/providers/pond/devicePresetAPI.tsx | 150 ++++++++++++++++++++++++ src/providers/pond/pond.tsx | 4 +- 4 files changed, 247 insertions(+), 95 deletions(-) create mode 100644 src/providers/pond/devicePresetAPI.tsx diff --git a/src/device/presets/devicePresetCard.tsx b/src/device/presets/devicePresetCard.tsx index b01def2..2839df3 100644 --- a/src/device/presets/devicePresetCard.tsx +++ b/src/device/presets/devicePresetCard.tsx @@ -6,7 +6,7 @@ import { DialogActions, DialogContent, DialogTitle, - Grid, + Grid2 as Grid, InputAdornment, MenuItem, Slider, @@ -19,7 +19,7 @@ import { DevicePreset } from "models/DevicePreset"; import { ObjectTypeString } from "objects/ObjectDescriber"; import { pond } from "protobuf-ts/pond"; import { useSnackbar } from "providers"; -// import { useDevicePresetAPI } from "providers/pond/devicePresetAPI"; +import { useDevicePresetAPI } from "providers/pond/devicePresetAPI"; import React, { useEffect, useState } from "react"; import { getTemperatureUnit } from "utils"; @@ -43,7 +43,7 @@ export default function DevicePresetCard(props: Props) { removeCallback, updateCallback } = props; - // const devicePresetAPI = useDevicePresetAPI(); + const devicePresetAPI = useDevicePresetAPI(); const [presetName, setPresetName] = useState(""); const [presetType, setPresetType] = useState(1); const [controllerType, setControllerType] = useState(1); @@ -81,22 +81,22 @@ export default function DevicePresetCard(props: Props) { p.settings.temperature = tempC; p.settings.humidity = hum; - // devicePresetAPI - // .addDevicePreset(p.name, p.settings, objectKey, typestring) - // .then(resp => { - // //get the temp key from the preset - // let temp = p.key; - // //update the key in the preset with the key that came back from the add - // p.key = resp.data.key; - // //use the callback function passing in the preset and the temp key - // if (addCallback) { - // addCallback(p, temp); - // } - // openSnack("New preset saved"); - // }) - // .catch(err => { - // openSnack("Failed to save new preset"); - // }); + devicePresetAPI + .addDevicePreset(p.name, p.settings, objectKey, typestring) + .then(resp => { + //get the temp key from the preset + let temp = p.key; + //update the key in the preset with the key that came back from the add + p.key = resp.data.key; + //use the callback function passing in the preset and the temp key + if (addCallback) { + addCallback(p, temp); + } + openSnack("New preset saved"); + }) + .catch(err => { + openSnack("Failed to save new preset"); + }); }; const updatePreset = () => { @@ -108,32 +108,32 @@ export default function DevicePresetCard(props: Props) { newPreset.settings.temperature = tempC; newPreset.settings.humidity = hum; - // devicePresetAPI - // .updateDevicePreset(newPreset.key, newPreset.name, newPreset.settings) - // .then(resp => { - // if (updateCallback) { - // updateCallback(oldPreset, newPreset); - // } - // openSnack("Preset Updated"); - // }) - // .catch(err => { - // openSnack("There was a problem updating the preset"); - // }); + devicePresetAPI + .updateDevicePreset(newPreset.key, newPreset.name, newPreset.settings) + .then(resp => { + if (updateCallback) { + updateCallback(oldPreset, newPreset); + } + openSnack("Preset Updated"); + }) + .catch(err => { + openSnack("There was a problem updating the preset"); + }); }; const removePreset = () => { - // devicePresetAPI - // .removeDevicePreset(preset.key) - // .then(resp => { - // openSnack("Preset has been deleted"); - // setOpenDeleteConfirmation(false); - // if (removeCallback) { - // removeCallback(preset); - // } - // }) - // .catch(err => { - // openSnack("There was a problem deleting this preset"); - // }); + devicePresetAPI + .removeDevicePreset(preset.key) + .then(resp => { + openSnack("Preset has been deleted"); + setOpenDeleteConfirmation(false); + if (removeCallback) { + removeCallback(preset); + } + }) + .catch(err => { + openSnack("There was a problem deleting this preset"); + }); }; const deleteConfirmation = () => { @@ -192,7 +192,7 @@ export default function DevicePresetCard(props: Props) { {deleteConfirmation()} - + - + {presetType !== pond.PresetType.PRESET_TYPE_UNKNOWN && controllerType !== pond.ControllerType.CONTROLLER_TYPE_UNKNOWN && ( @@ -216,7 +216,7 @@ export default function DevicePresetCard(props: Props) { )} - + {/* type */} - + {/* controller type */} {/* temp slider */} {isMobile ? ( - + ) : ( - + Temperature - + - + + ) : ( - + Humidity - + - + { - let tempOrgs: Map = new Map(); + let tempOrgs: Map = new Map(); resp.data.accounts.forEach(org => { - let organization = pond.JDAccount.fromObject(org); + let organization = pond.LibraCartAccount.fromObject(org); tempOrgs.set(organization.key, organization); }); setOrganizations(tempOrgs); @@ -70,40 +70,40 @@ export default function LibraCart() { }); }; - const fieldOptions = () => { - return ( - - { - setFieldAccordion(expanded); - }}> - }>Field Data - - - - { - //setFields(!fields); - updateOrgData(checked, pond.DataOption.DATA_OPTION_FIELDS); - }} - /> - } - /> - - - View your data from Libra Cart on your visual Farm - - - - - - ); - }; + // const fieldOptions = () => { + // return ( + // + // { + // setFieldAccordion(expanded); + // }}> + // }>Field Data + // + // + // + // { + // //setFields(!fields); + // updateOrgData(checked, pond.DataOption.DATA_OPTION_FIELDS); + // }} + // /> + // } + // /> + // + // + // View your data from Libra Cart + // + // + // + // + // + // ); + // }; return ( @@ -117,7 +117,7 @@ export default function LibraCart() {