From f8b5aeed654164abd054f62e429ab2379122dcae Mon Sep 17 00:00:00 2001 From: Benedikt Nordhoff Date: Mon, 7 Aug 2023 11:08:40 +0200 Subject: [PATCH] Display more fields --- src/components/SensorTooltip/index.tsx | 59 ++++++++++++++++++++++++-- src/hooks/useMoistureData.ts | 12 ++++-- src/model/models.ts | 9 +++- 3 files changed, 71 insertions(+), 9 deletions(-) diff --git a/src/components/SensorTooltip/index.tsx b/src/components/SensorTooltip/index.tsx index 9436d51..bd4a9ac 100644 --- a/src/components/SensorTooltip/index.tsx +++ b/src/components/SensorTooltip/index.tsx @@ -25,6 +25,12 @@ const styles = mergeStyleSets({ fontWeight: FontWeights.semilight, }, ], + footer: [ + { + margin: 0, + marginTop: "10px", + }, + ], link: [ theme.fonts.medium, { @@ -34,17 +40,62 @@ const styles = mergeStyleSets({ }); const SensorTooltip = ({ record }: { record: SensorInfo }) => { + const format = (n: number) => + new Intl.NumberFormat("de-DE", { + maximumFractionDigits: 2, + }).format(n); return ( <>
- Feuchte: {Number(record.soil_moisture).toFixed(2)} % + Bodenfeuchte {format(record.soil_moisture)} %
- - Letzte Aktualisierung: {record.timestamp.toLocaleString()} - + + + {record.soil_temperature != null && ( + + + + + )} + {record.soil_conductivity != null && ( + + + + + )} + {record.battery != null && ( + + + + + )} + +
+ Bodentemperatur + + + {format(record.soil_temperature)} °C + +
+ Leitfähigkeit + + + {format(record.soil_conductivity)} μS/cm + +
+ Batteriespannung + + {format(record.battery)} V +
+
+ + Letzte Aktualisierung:{" "} + {record.last_updated.toLocaleString()} + +
); diff --git a/src/hooks/useMoistureData.ts b/src/hooks/useMoistureData.ts index eaefcda..24894ac 100644 --- a/src/hooks/useMoistureData.ts +++ b/src/hooks/useMoistureData.ts @@ -14,17 +14,21 @@ const MOCK_DATA: MoistureDataDto = { altitude: 0, soil_moisture: 13.37, device: "mock", + last_update: "1970-01-01 00:00:00", }, ], }; function processData(data: MoistureDataDto): MoistureData { - const timestamp = new Date( - /\+|Z/i.test(data.timestamp) ? data.timestamp : data.timestamp + "Z" - ); + function toDate(timestamp: string): Date { + return new Date(/\+|Z/i.test(timestamp) ? timestamp : timestamp + "Z"); + } + const timestamp = toDate(data.timestamp); return { records: data.records.map((record) => { - return { ...record, timestamp }; + const last_updated = toDate(record.last_update); + console.log(record.last_update); + return { ...record, last_updated }; }), timestamp, }; diff --git a/src/model/models.ts b/src/model/models.ts index 6cb8b3f..b4bdaf1 100644 --- a/src/model/models.ts +++ b/src/model/models.ts @@ -4,6 +4,10 @@ export interface SensorInfoDto { latitude: number; longitude: number; soil_moisture: number; + soil_temperature?: number; + soil_conductivity?: number; + battery?: number; + last_update: string; } export interface MoistureDataDto { records: SensorInfoDto[]; @@ -17,7 +21,10 @@ export interface SensorInfo { latitude: number; longitude: number; soil_moisture: number; - timestamp: Date; + soil_temperature?: number; + soil_conductivity?: number; + battery?: number; + last_updated: Date; } export interface MoistureData {