diff --git a/package-lock.json b/package-lock.json index c150062..bc69395 100644 --- a/package-lock.json +++ b/package-lock.json @@ -42,7 +42,7 @@ "mui-tel-input": "^7.0.0", "notistack": "^3.0.1", "openweathermap-ts": "^1.2.10", - "protobuf-ts": "git+https://gitlab+deploy-token-50627:hv8mB4WkyvtjBpJKU1rN@gitlab.com/brandx/protobuf-ts.git#staging", + "protobuf-ts": "git+https://gitlab+deploy-token-50627:hv8mB4WkyvtjBpJKU1rN@gitlab.com/brandx/protobuf-ts.git#master", "query-string": "^9.2.1", "react": "^18.3.1", "react-beautiful-dnd": "^13.1.1", @@ -10953,7 +10953,7 @@ }, "node_modules/protobuf-ts": { "version": "1.0.0", - "resolved": "git+https://gitlab+deploy-token-50627:hv8mB4WkyvtjBpJKU1rN@gitlab.com/brandx/protobuf-ts.git#c9ef7906fd97cda8ef4bd149ec4a796159a7c067", + "resolved": "git+https://gitlab+deploy-token-50627:hv8mB4WkyvtjBpJKU1rN@gitlab.com/brandx/protobuf-ts.git#bcf085706791036841f7047a5b37f00c18e54574", "dependencies": { "protobufjs": "^6.8.8" } diff --git a/src/device/DeviceViewer.tsx b/src/device/DeviceViewer.tsx index e03dae3..5836f28 100644 --- a/src/device/DeviceViewer.tsx +++ b/src/device/DeviceViewer.tsx @@ -31,6 +31,7 @@ import React, { useCallback, useEffect, useState } from "react"; //import { Redirect } from "react-router"; import { or } from "utils/types"; import DeviceActions from "./DeviceActions"; +import { getContextKeys, getContextTypes } from "pbHelpers/Context"; const useStyles = makeStyles((theme: Theme) => ({ title: { @@ -97,45 +98,28 @@ export default function Device(props: Props) { const load = useCallback(() => { if (user.id() === "") return; setIsLoading(true); - //let devicePromise = deviceAPI.get(deviceID); - let userPromise = userAPI.getUser(user.id(), deviceScope(deviceID.toString())); - let componentsPromise = componentAPI.list( - deviceID, - undefined, - [deviceID.toString()], - ["device"], - true, - as - ); - let interactionsPromise = interactionsAPI.listInteractionsByDevice(deviceID, undefined, as); - let groupPromise: Promise = Promise.resolve(undefined); - Promise.all([userPromise, componentsPromise, interactionsPromise, groupPromise]) - .then(([userRes, componentsRes, interactionsRes]) => { - //let rDevice = DeviceModel.any(deviceRes.data); - let rawComponents: Array = or(componentsRes.data.components, []); - let rComponents: Map = new Map(); - rawComponents.forEach((rawComponent: any) => { - let component = Component.any(rawComponent); - rComponents.set(component.key(), component); - }); + deviceAPI.getPageData(deviceID, getContextKeys(), getContextTypes(), as).then(resp => { + console.log(resp) + let rawComponents: Array = or(resp.data.components, []); + let rComponents: Map = new Map(); + rawComponents.forEach((rawComponent: any) => { + let component = Component.any(rawComponent); + rComponents.set(component.key(), component); + }); + setComponents(rComponents); - setComponents(rComponents); - - setInteractions(interactionsRes); - setPermissions(userRes.permissions); - setPreferences(userRes.preferences); - - setDevice(props.device); - setLongitude(props.device.status.longitude ? props.device.status.longitude : NaN); - setLatitude(props.device.status.latitude ? props.device.status.latitude : NaN); - let available = FindAvailablePositions( - Array.from(rComponents.values()), - props.device.settings.product - ); - setAvailablePositions(available.GetAvailability()); - setAvailableOffsets(available.offsetAvailability); - }) - .catch((err: any) => { + setInteractions(resp.data.interactions.map(i => Interaction.create(i))) + setPermissions(resp.data.permissions) + setDevice(props.device); + setLongitude(props.device.status.longitude ? props.device.status.longitude : NaN); + setLatitude(props.device.status.latitude ? props.device.status.latitude : NaN); + let available = FindAvailablePositions( + Array.from(rComponents.values()), + props.device.settings.product + ); + setAvailablePositions(available.GetAvailability()); + setAvailableOffsets(available.offsetAvailability); + }).catch(err => { setDevice(DeviceModel.create()); setComponents(new Map()); setInteractions([]); @@ -145,8 +129,9 @@ export default function Device(props: Props) { setPreferences(pond.UserPreferences.create()); setInvalidDevice(true); error(err); - }) - .finally(() => setIsLoading(false)); + }).finally(() => { + setIsLoading(false) + }) usageAPI .getUsage(deviceID, moment().subtract(1, "days")) .then((res: any) => {