diff --git a/components/ShowAddStationPopup.js b/components/ShowAddStationPopup.js index 5fb7a7eeb..7bbffd5f3 100644 --- a/components/ShowAddStationPopup.js +++ b/components/ShowAddStationPopup.js @@ -17,18 +17,6 @@ const ShowAddStationPopup = ({ onClose, map, latlng }) => { const [locationDeviceData, setLocationDeviceData] = useState([]); const [deviceName, setDeviceName] = useState(""); - /* useEffect(() => { - if (map && loadData) { - - console.log("Map and loadData are defined in ShowAddStationPopup.js", map); - console.log("loadData object in ShowAddStationPopup.js:", loadData); - // Your code here - }else{ - console.log("Map and loadData are not defined in ShowAddStationPopup.js"); - } - }, [map, loadData]); */ - - // In Kontextmenü-Formular Typen anzeigen useEffect(() => { const fetchpoiTypData = async () => { try { @@ -51,40 +39,8 @@ const ShowAddStationPopup = ({ onClose, map, latlng }) => { fetchpoiTypData(); }, []); - //-----------------handleSubmit------------------- - const handleSubmit = async (event) => { - event.preventDefault(); - const formData = { - name, - poiTypeId, - latitude, - longitude, - }; - - const response = await fetch("/api/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(); - } - }; //--------------------------------------------------------------------------------------- - useEffect(() => { + /* useEffect(() => { // Funktion zum Abrufen der Daten von der API -> DB talas_v5.location_device const fetchData = async () => { try { @@ -101,7 +57,7 @@ const ShowAddStationPopup = ({ onClose, map, latlng }) => { }; fetchData(); - }, []); // Leerarray als Dependency, um den Effekt nur beim Laden der Komponente auszuführen + }, []); // Leerarray als Dependency, um den Effekt nur beim Laden der Komponente auszuführen */ //------------------------------------------------------------------------------------------ useEffect(() => { @@ -127,6 +83,41 @@ const ShowAddStationPopup = ({ onClose, map, latlng }) => { }, []); //------------------------------------------------------------------------------------------ + //-----------------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/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 (