idLD foreign key von talas_v5.location_device in poi Tabelle ,in der Spalte idLD speichern beim hinzufügen eines POI auf die Map

This commit is contained in:
ISA
2024-05-16 10:06:11 +02:00
parent 11b09c2cda
commit f2ecbc522b
2 changed files with 47 additions and 51 deletions

View File

@@ -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 (
<form onSubmit={handleSubmit} className="m-0 p-2 w-full ">