From 8c85b2dbf3ed49ced6ec42881bf82d32affafb18 Mon Sep 17 00:00:00 2001 From: ISA Date: Mon, 16 Sep 2024 10:30:49 +0200 Subject: [PATCH] git commit -m "Remove redundant ShowAddStationPopup.js as its functionality is duplicated by AddPoiModalWindow.js" --- components/ShowAddStationPopup.js | 201 ------------------------------ 1 file changed, 201 deletions(-) delete mode 100644 components/ShowAddStationPopup.js diff --git a/components/ShowAddStationPopup.js b/components/ShowAddStationPopup.js deleted file mode 100644 index a303772fe..000000000 --- a/components/ShowAddStationPopup.js +++ /dev/null @@ -1,201 +0,0 @@ -// components/ShowAddStationPopup.js -import React, { useState, useEffect, use } from "react"; -import ReactDOM from "react-dom"; -import { useRecoilValue, useRecoilState, useSetRecoilState } from "recoil"; -import { readPoiMarkersStore } from "../store/selectors/readPoiMarkersStore"; -import { poiReadFromDbTriggerAtom } from "../store/atoms/poiReadFromDbTriggerAtom"; - -const ShowAddStationPopup = ({ onClose, map, latlng }) => { - const [poiTypData, setpoiTypData] = useState(); // Recoil State verwenden - const [name, setName] = useState(""); - const [poiTypeId, setPoiTypeId] = useState(""); // Initialize as string - const [poiTypeName, setPoiTypeName] = useState(""); // Initialize as string - const [latitude] = useState(latlng.lat.toFixed(5)); - const [longitude] = useState(latlng.lng.toFixed(5)); - const setLoadData = useSetRecoilState(readPoiMarkersStore); - const setTrigger = useSetRecoilState(poiReadFromDbTriggerAtom); - const [locationDeviceData, setLocationDeviceData] = useState([]); - const [deviceName, setDeviceName] = useState(""); - - useEffect(() => { - const fetchpoiTypData = async () => { - try { - const response = await fetch("/api/talas_v5_DB/poiTyp/readPoiTyp"); - const data = await response.json(); - setpoiTypData(data); - if (data && data.length > 0) { - setPoiTypeId(data[0].idPoiTyp); // Set initial poiTypeId to the id of the first poiType - setPoiTypeName(data[1].name); // Set initial poiTypeName to the name of the first poiType - console.log( - "Initial poiTypeId set in ShowAddStationPopup.js :", - data[0].idPoiTyp - ); - } - } catch (error) { - console.error("Fehler beim Abrufen der poiTyp Daten:", error); - } - }; - - fetchpoiTypData(); - }, []); - - //--------------------------------------------------------------------------------------- - /* 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/talas5/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(); - }, []); - - //------------------------------------------------------------------------------------------ - //-----------------handleSubmit------------------- - const handleSubmit = async (event) => { - event.preventDefault(); - const formData = { - name, - poiTypeId, - latitude, - longitude, - idLD: locationDeviceData.find((device) => device.name === deviceName) - .idLD, - }; - - const response = await fetch("/api/talas_v5_DB/pois/addLocation", { - method: "POST", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify(formData), - }); - - if (response.ok) { - setTrigger((trigger) => { - console.log("Aktueller Trigger-Wert:", trigger); // Vorheriger Wert - const newTrigger = trigger + 1; - console.log("Neuer Trigger-Wert:", newTrigger); // Aktualisierter Wert - onClose(); - return newTrigger; - }); - } else { - console.error("Fehler beim Hinzufügen des POI"); - } - - if (map && typeof map.closePopup === "function") { - map.closePopup(); - } - }; - //-----------------handleSubmit------------------- - - return ( -
-
- - setName(e.target.value)} - placeholder="Name der Station" - className="block p-2 w-full border-2 border-gray-200 rounded-md text-sm" - /> -
- - {/* {locationDeviceData.----------------------------------------------*/} -
- - -
- {/* {locationDeviceData.----------------------------------------------*/} -
- - -
-
-
- -
-
- -
-
- - -
- ); -}; - -export default ShowAddStationPopup;