From 31803907b9d8f5529d2748cd5f47e5c7e660cadf Mon Sep 17 00:00:00 2001 From: ISA Date: Thu, 2 May 2024 19:48:26 +0200 Subject: [PATCH] Das property poiTypeId in handleSubmit in der Console --- components/ShowAddStationPopup.js | 54 +++++++++++++------------------ config/config.js | 8 ++++- pages/api/[...path].js | 3 +- 3 files changed, 31 insertions(+), 34 deletions(-) diff --git a/components/ShowAddStationPopup.js b/components/ShowAddStationPopup.js index 79769c20d..e471dce1b 100644 --- a/components/ShowAddStationPopup.js +++ b/components/ShowAddStationPopup.js @@ -1,48 +1,40 @@ -// components/ShowAddStationPopup.js: import React, { useState, useEffect } from "react"; import ReactDOM from "react-dom"; const ShowAddStationPopup = ({ map, latlng }) => { - const [poiTypData2, setpoiTypData2] = useState(); // Recoil State verwenden - + const [poiTypData2, setPoiTypData2] = useState(); // Recoil State verwenden const [name, setName] = useState(""); - const [poiTypeId, setPoiTypeId] = useState(""); + const [poiTypeId, setPoiTypeId] = useState(""); // Initialize as string const [latitude] = useState(latlng.lat.toFixed(5)); const [longitude] = useState(latlng.lng.toFixed(5)); - // Effekt zum Ausgeben von poiTypData2 in der Konsole useEffect(() => { - console.log("poiTypData2 in ShowAddStationPopup.js :", poiTypData2); - }, [poiTypData2]); - - //------------------------------------------ - // Funktion zum Abrufen der poiTyp Daten - - useEffect(() => { - const fetchpoiTypData2 = async () => { + const fetchPoiTypData2 = async () => { try { const response = await fetch("/api/poiTyp"); const data = await response.json(); - setpoiTypData2(data); // Daten im Recoil State speichern + setPoiTypData2(data); + if (data && data.length > 0) { + setPoiTypeId(data[0].idPoiTyp); // Set initial poiTypeId to the id 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); } }; - fetchpoiTypData2(); + fetchPoiTypData2(); }, []); - // Effekt zum Loggen der poiTypData2, wenn sie sich ändern - useEffect(() => { - console.log("poiTypData2 aktualisiert:", poiTypData2); - }, [poiTypData2]); - - //---------------------------------------------------- - const handleSubmit = (event) => { event.preventDefault(); - console.log({ name, poiTypeId, latitude, longitude }); - map.closePopup(); + console.log("Daten von ShowAddStationPopup: ", { + name, // Name der Station + poiTypeId, // Typ der Station, logged as idPoiTyp + latitude, // Breitengrad + longitude, // Längengrad + }); + //map.closePopup(); }; return ( @@ -58,7 +50,7 @@ const ShowAddStationPopup = ({ map, latlng }) => { value={name} onChange={(e) => setName(e.target.value)} placeholder="Name der Station" - className="block p-2 w-full border-2 border-gray-200 rounded-md text-sm" // Use w-full for full width + className="block p-2 w-full border-2 border-gray-200 rounded-md text-sm" />
@@ -70,17 +62,15 @@ const ShowAddStationPopup = ({ map, latlng }) => { name="idPoiTyp2" value={poiTypeId} onChange={(e) => setPoiTypeId(e.target.value)} - className="block p-2 w-full border-2 border-gray-200 rounded-md text-sm" // Adjusted width + className="block p-2 w-full border-2 border-gray-200 rounded-md text-sm" > - {Array.isArray(poiTypData2) && - poiTypData2.map((poiTyp, index) => ( - ))}
-
@@ -104,7 +94,7 @@ const ShowAddStationPopup = ({ map, latlng }) => { name="lng" value={longitude} readOnly - className="block p-2 w-full border-2 border-gray-200 rounded-md text-sm" // Adjusted width + className="block p-2 w-full border-2 border-gray-200 rounded-md text-sm" />