From 11b09c2cda80f74e0601e15fb0657b091fc2cc6c Mon Sep 17 00:00:00 2001 From: ISA Date: Thu, 16 May 2024 08:45:04 +0200 Subject: [PATCH] device location dropdaown menu --- components/ShowAddStationPopup.js | 66 +++++++++++++++++++++++++++ pages/api/talas_v5/location_device.js | 42 +++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 pages/api/talas_v5/location_device.js diff --git a/components/ShowAddStationPopup.js b/components/ShowAddStationPopup.js index a52a2ef11..5fb7a7eeb 100644 --- a/components/ShowAddStationPopup.js +++ b/components/ShowAddStationPopup.js @@ -14,6 +14,8 @@ const ShowAddStationPopup = ({ onClose, map, latlng }) => { const [longitude] = useState(latlng.lng.toFixed(5)); const setLoadData = useSetRecoilState(readPoiMarkersStore); const setTrigger = useSetRecoilState(poiReadFromDbTriggerAtom); + const [locationDeviceData, setLocationDeviceData] = useState([]); + const [deviceName, setDeviceName] = useState(""); /* useEffect(() => { if (map && loadData) { @@ -81,6 +83,50 @@ const ShowAddStationPopup = ({ onClose, map, latlng }) => { map.closePopup(); } }; + //--------------------------------------------------------------------------------------- + useEffect(() => { + // Funktion zum Abrufen der Daten von der API -> DB talas_v5.location_device + const fetchData = async () => { + try { + const response = await fetch("/api/talas_v5/location_device"); // Pfad zu Ihrem API-Endpunkt + const data = await response.json(); + setLocationDeviceData(data); // Setzt den Zustand mit den abgerufenen Daten + console.log("Abgerufene Standort- und Gerätedaten:", data); + } catch (error) { + console.error( + "Fehler beim Abrufen der Standort- und Gerätedaten:", + error + ); + } + }; + + fetchData(); + }, []); // Leerarray als Dependency, um den Effekt nur beim Laden der Komponente auszuführen + + //------------------------------------------------------------------------------------------ + useEffect(() => { + // Funktion zum Abrufen der Daten von der API -> DB talas_v5.location_device + const fetchData = async () => { + try { + const response = await fetch("/api/talas_v5/location_device"); + const data = await response.json(); + setLocationDeviceData(data); + if (data.length > 0) { + setDeviceName(data[0].name); // Setzen des anfänglichen Gerätenamens + } + console.log("Abgerufene Standort- und Gerätedaten:", data); + } catch (error) { + console.error( + "Fehler beim Abrufen der Standort- und Gerätedaten:", + error + ); + } + }; + + fetchData(); + }, []); + + //------------------------------------------------------------------------------------------ return (
@@ -117,6 +163,26 @@ const ShowAddStationPopup = ({ onClose, map, latlng }) => { ))} + {/* {locationDeviceData.----------------------------------------------*/} +
+ + +
+ {/* {locationDeviceData.----------------------------------------------*/}