From 7a7b7a00c9b07c5ba5d2c0ea25fc9290a4949a5d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Daniel=20M=C3=A4ckelmann?=
<6890706+n1kPLV@users.noreply.github.com>
Date: Mon, 4 Sep 2023 18:45:37 +0200
Subject: [PATCH] display tracker batery information (if known)
---
Website/src/app/components/dynlist.tsx | 25 ++++++++++++++-----
Website/src/app/components/tracker.tsx | 34 ++++++++++++++++++++------
Website/src/app/list/page.tsx | 3 +--
Website/src/utils/api.ts | 1 +
Website/src/utils/helpers.ts | 18 +++++++-------
5 files changed, 56 insertions(+), 25 deletions(-)
diff --git a/Website/src/app/components/dynlist.tsx b/Website/src/app/components/dynlist.tsx
index 2e084af3..14713296 100644
--- a/Website/src/app/components/dynlist.tsx
+++ b/Website/src/app/components/dynlist.tsx
@@ -5,6 +5,7 @@ import { Vehicle } from "@/utils/api";
import useSWR from "swr";
import { coordinateFormatter } from "@/utils/helpers";
import Link from "next/link";
+import TrackerCharge from "@/app/components/tracker";
const fetcher = async ([url, track_id]: [url: string, track_id: number]) => {
const res = await fetch(`${url}/${track_id}`, { method: "get" });
@@ -54,11 +55,17 @@ export default function DynamicList({ server_vehicles, track_id, logged_in, trac
Name |
- geog. Breite |
- geog. Länge |
- Richtung |
+
+ geog. Breite
+ |
+
+ geog. Länge
+ |
+
+ Richtung
+ |
Batterieladung |
- Auf Karte anzeigen |
+ Auf Karte zeigen |
@@ -74,8 +81,14 @@ export default function DynamicList({ server_vehicles, track_id, logged_in, trac
{v.heading ? coordinateFormatter.format(v.heading) : "unbekannt"}
|
- {{}.toString()} |
-
+ |
+
+ {v.trackerIds.map(trackerId => (
+
+ ))}
+
+ |
+
Link
diff --git a/Website/src/app/components/tracker.tsx b/Website/src/app/components/tracker.tsx
index 8d35c5b5..937e8d28 100644
--- a/Website/src/app/components/tracker.tsx
+++ b/Website/src/app/components/tracker.tsx
@@ -1,11 +1,29 @@
-import {getFetcher, TrackerIdRoute} from "@/utils/fetcher";
+import { getFetcher, TrackerIdRoute } from "@/utils/fetcher";
import useSWR from "swr";
+import { batteryLevelFormatter } from "@/utils/helpers";
-export default function TrackerCharge({trackerId}: {trackerId: string}) {
+export default function TrackerCharge({ trackerId }: { trackerId: string }) {
+ const safeTrackerId = encodeURIComponent(trackerId);
+ const { data: tracker_data } = useSWR(`/webapi/tracker/read/${safeTrackerId}`, getFetcher);
- const safeTrackerId = encodeURIComponent(trackerId);
- const {data: tracker_data} = useSWR(`/webapi/tracker/read/${safeTrackerId}`, getFetcher)
-
- return ( {tracker_data && <>{tracker_data.id}: {tracker_data.data ?? "unbekannt"} %>} )
-
-}
\ No newline at end of file
+ return (
+ <>
+ {tracker_data && (
+
+
+ {tracker_data.id}
+
+ {tracker_data.id}
+
+
+
+ {tracker_data.battery == undefined ? "?" : batteryLevelFormatter.format(tracker_data.battery)}
+
+
+ )}
+ >
+ );
+}
diff --git a/Website/src/app/list/page.tsx b/Website/src/app/list/page.tsx
index fb2d82c7..b0512c73 100644
--- a/Website/src/app/list/page.tsx
+++ b/Website/src/app/list/page.tsx
@@ -25,9 +25,8 @@ export default async function Home() {
return [undefined, [], [], []];
});
- console.log("server vehicles", server_vehicles);
return (
-
+
(f: () => T): T | undefined {
try {
return f();
} catch (e) {
- return
+ return;
}
}
export function apiError(statusCode: number): NextResponse {
- const statusText = http.STATUS_CODES[statusCode]
+ const statusText = http.STATUS_CODES[statusCode];
return new NextResponse(statusText + "\r\n", {
status: statusCode,
@@ -60,5 +60,5 @@ export function getUsername(token: string): string {
if (!isTokenPayload(payload)) {
throw new TypeError("Not a valid jwt auth token");
}
- return payload.username
+ return payload.username;
}
|