fix: close context menu 2 seconds before API call to prevent errors

- Implemented logic to monitor the context menu state and ensure it closes 2 seconds before the 20-second interval API call
- Added functionality to log remaining time while the context menu is open for better debugging
- Refactored interval handling to reset remaining time and close the context menu properly
- Addressed runtime error related to null context menu handling
This commit is contained in:
ISA
2024-09-11 14:53:13 +02:00
parent 30f671e1c1
commit 8a01ca8814
3 changed files with 42 additions and 84 deletions

View File

@@ -76,6 +76,7 @@ import { polylineEventsDisabledState } from "../store/atoms/polylineEventsDisabl
import { disablePolylineEvents, enablePolylineEvents } from "../utils/setupPolylines";
const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
const [editMode, setEditMode] = useState(false); // editMode Zustand
const { deviceName, setDeviceName } = useMapComponentState();
const { poiTypData, isPoiTypLoaded } = usePoiTypData("/api/talas_v5_DB/poiTyp/readPoiTyp");
//const [deviceName, setDeviceName] = useState("");
@@ -656,20 +657,23 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
}
}, [map]);
//--------------------------------------------
// contextmenü Error "Contextmenu ist nicht vorhanden"
useEffect(() => {
if (map) {
// Überprüfe, ob die Karte und das Contextmenu existieren
if (map.contextmenu) {
console.log("Contextmenu ist vorhanden");
// Hier kannst du deine Logik für das Contextmenu hinzufügen
map.contextmenu.hide(); // Beispiel: Contextmenu verstecken
} else {
console.warn("Contextmenu ist nicht vorhanden");
const initializeContextMenu = () => {
if (map) {
map.whenReady(() => {
setTimeout(() => {
if (map.contextmenu) {
console.log("Contextmenu ist vorhanden");
} else {
console.warn("Contextmenu ist nicht verfügbar.");
}
}, 500);
});
}
}
}, [map]);
};
initializeContextMenu();
}, [map]);
return (
<>
<ToastContainer />