feat(PoiUpdateModal): Display correct POI type in dropdown on modal open

- Added logic to store the selected POI type in localStorage during POI selection.
- Updated PoiUpdateModal to pre-select the correct POI type from localStorage when opening the modal.
- Implemented fallback to fetch POI types if not found in localStorage.
- Ensured the selected device is also pre-filled in the dropdown.
This commit is contained in:
ISA
2024-09-13 10:21:07 +02:00
parent 56f4a585ae
commit 864644c543
3 changed files with 34 additions and 236 deletions

View File

@@ -1,37 +1,35 @@
// utils/handlePoiSelect.js
const handlePoiSelect = async (poiData, setSelectedPoi, setLocationDeviceData, setDeviceName, poiLayerRef, poiTypMap) => {
setSelectedPoi(poiData); // poiData should be the data of the selected POI
//console.log("Selected POI:", poiData);
//console.log("Selected POI idLD:", poiData.deviceId);
setSelectedPoi(poiData); // Setzt das ausgewählte POI
try {
const response = await fetch("/api/talas_v5_DB/locationDevice/locationDevices");
const data = await response.json();
setLocationDeviceData(data);
//console.log("Standort- und Gerätedaten:", data);
const currentDevice = data.find((device) => device.idLD === poiData.deviceId);
if (currentDevice) {
setDeviceName(currentDevice.name);
//console.log("Current Device name in poiUpdate2:", currentDevice.name);
// Update the marker popup with the device name and type
// Hier speichern wir den POI-Typ im localStorage
const poiTypeName = poiTypMap.get(poiData.idPoiTyp);
localStorage.setItem("selectedPoiType", poiTypeName);
// Optional: Update des Markers mit dem POI-Typ
const marker = poiLayerRef.current.getLayers().find((m) => m.options.id === poiData.id);
if (marker) {
marker.setPopupContent(
`
<div>
<b class="text-xl text-black-700">${poiData.description || "Unbekannt"}</b><br>
${currentDevice.name}<br>
${poiTypMap.get(poiData.idPoiTyp) || "Unbekannt"}<br>
</div>
`,
);
marker.setPopupContent(`
<div>
<b class="text-xl text-black-700">${poiData.description || "Unbekannt"}</b><br>
${currentDevice.name}<br>
${poiTypeName || "Unbekannt"}<br>
</div>
`);
marker.openPopup();
}
}
} catch (error) {
console.error("Fehler beim Abrufen der Gerätedaten2:", error);
console.error("Fehler beim Abrufen der Gerätedaten:", error);
setLocationDeviceData([]);
}
};