feat(context-menu): Fix POI hinzufügen Modal und State-Handling

- `useMapContextMenu.js`:
  - `openPoiModal` in `addItemsToMapContextMenu` integriert, um Zugriff auf `setShowCoordinatesModal` und `setShowPoiModal` zu ermöglichen.
  - `setShowCoordinatesModal` wird korrekt als Parameter übergeben und verwaltet.
  - `POI hinzufügen`-Eintrag im Kontextmenü wurde verbessert.

- `MapComponent.js`:
  - `setShowCoordinatesModal`, `setShowPoiModal` und `setPopupCoordinates` werden jetzt korrekt an `addItemsToMapContextMenu` übergeben.
  - `ShowAddStationPopup` Modal öffnet sich jetzt korrekt und überlagert die Seite.
  - UI-Verbesserungen für Modale und Fix für doppeltes Öffnen von Modalen.

Fixes: Problem, dass mehrere Modale gleichzeitig geöffnet wurden und `setShowCoordinatesModal` nicht definiert war.
This commit is contained in:
Ismail Ali
2025-03-09 09:37:01 +01:00
parent e4bb12fe18
commit ffb76857c7
3 changed files with 37 additions and 13 deletions

View File

@@ -174,10 +174,14 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
const [newCoords, setNewCoords] = useState(null);
const [tempMarker, setTempMarker] = useState(null);
const [showPoiModal, setShowPoiModal] = useState(false);
const [showCoordinatesModal, setShowCoordinatesModal] = useState(false);
const [popupCoordinates, setPopupCoordinates] = useState(null);
/*
const [popupCoordinates, setPopupCoordinates] = useState({
lat: 52.52,
lng: 13.405,
});
}); */
const [popupVisible, setPopupVisible] = useState(false);
const handleAddStation = (stationData) => {
@@ -1007,12 +1011,20 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
}
}, [map, menuItemAdded, hasRights]); */
//--------------------------------------------
useEffect(() => {
if (map && !menuItemAdded) {
addItemsToMapContextMenu(map, menuItemAdded, setMenuItemAdded, openPopupWithCoordinates);
addItemsToMapContextMenu(
map,
menuItemAdded,
setMenuItemAdded,
setShowCoordinatesModal,
setShowPoiModal,
setPopupCoordinates,
openPopupWithCoordinates // Diese Funktion wird jetzt übergeben!
);
}
}, [map, menuItemAdded]);
//--------------------------------------------
// Beim ersten Client-Render den Wert aus localStorage laden
useEffect(() => {
@@ -1034,7 +1046,11 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
return (
<>
{popupVisible && <ShowAddStationPopup latlng={popupCoordinates} onClose={() => setPopupVisible(false)} map={map} />}
{/* Zeigt das Koordinaten-Modal, wenn `showCoordinatesModal` true ist */}
{showCoordinatesModal && <CoordinateModal latlng={popupCoordinates} onClose={() => setShowCoordinatesModal(false)} />}
{/* Zeigt das POI-Modal, wenn `showPoiModal` true ist */}
{showPoiModal && <ShowAddStationPopup latlng={popupCoordinates} onClose={() => setShowPoiModal(false)} />}
<ToastContainer />
<div>{showPoiUpdateModal && <PoiUpdateModal onClose={() => setShowPoiUpdateModal(false)} poiData={currentPoiData} onSubmit={() => {}} latlng={popupCoordinates} />}</div>