From 6c7b3722910528f8c5462eae1e8b1f1ec272e319 Mon Sep 17 00:00:00 2001 From: Ismail Ali Date: Mon, 10 Mar 2025 22:21:36 +0100 Subject: [PATCH] Seite neu laden wenn die Fehler kommt , aber wird kurz angezeigt --- components/mainComponent/MapComponent.js | 29 +++++++++++++++++++----- config/appVersion.js | 2 +- redux/slices/polylineContextMenuSlice.js | 12 +++++++++- utils/polylines/setupPolylines.js | 18 ++++++++++----- 4 files changed, 47 insertions(+), 14 deletions(-) diff --git a/components/mainComponent/MapComponent.js b/components/mainComponent/MapComponent.js index a627cad13..447b0b211 100644 --- a/components/mainComponent/MapComponent.js +++ b/components/mainComponent/MapComponent.js @@ -84,8 +84,10 @@ import { updateCountdown, closePolylineContextMenu, forceCloseContextMenu } from const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => { const dispatch = useDispatch(); - const isPolylineContextMenuOpen = useSelector((state) => state.polylineContextMenu.isOpen); const countdown = useSelector((state) => state.polylineContextMenu.countdown); + const countdownActive = useSelector((state) => state.polylineContextMenu.countdownActive); + const isPolylineContextMenuOpen = useSelector((state) => state.polylineContextMenu.isOpen); + const contextMenuState = useSelector((state) => state.polylineContextMenu); const polylinePosition = contextMenuState.position ? L.latLng(contextMenuState.position.lat, contextMenuState.position.lng) : null; @@ -1065,13 +1067,13 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => { //-------------------------------------- useEffect(() => { - if (isPolylineContextMenuOpen) { - console.log("🔄 Starte Redux-Countdown für Kontextmenü!"); + if (isPolylineContextMenuOpen && countdownActive) { + //console.log("🔄 Starte Redux-Countdown für Kontextmenü!"); const interval = setInterval(() => { dispatch(updateCountdown()); - console.log(`⏳ Redux Countdown: ${countdown} Sekunden`); + // console.log(`⏳ Redux Countdown: ${countdown} Sekunden`); if (countdown <= 2) { console.log("🚀 Kontextmenü wird wegen Countdown < 2 geschlossen."); @@ -1089,8 +1091,7 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => { clearInterval(interval); }; } - }, [isPolylineContextMenuOpen, countdown, dispatch, window.map]); - + }, [isPolylineContextMenuOpen, countdown, countdownActive, dispatch, window.map]); //---------------------------------- useEffect(() => { if (map) { @@ -1100,6 +1101,22 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => { }, [map]); //--------------------------------------- + useEffect(() => { + window.onerror = function (message, source, lineno, colno, error) { + if (message.includes("Cannot read properties of null (reading 'contextmenu')")) { + console.warn("⚠️ Fehler mit `contextmenu` erkannt - Neuladen der Seite."); + setTimeout(() => { + window.location.reload(); + }, 2000); // **Seite nach 2 Sekunden neu laden** + } + }; + + return () => { + window.onerror = null; // **Fehlerbehandlung entfernen, wenn Komponente unmounted wird** + }; + }, []); + + //--------------------------------------------- return ( <> diff --git a/config/appVersion.js b/config/appVersion.js index d84cfacff..98a0d9bbe 100644 --- a/config/appVersion.js +++ b/config/appVersion.js @@ -1,2 +1,2 @@ // /config/appVersion -export const APP_VERSION = "1.1.43"; +export const APP_VERSION = "1.1.44"; diff --git a/redux/slices/polylineContextMenuSlice.js b/redux/slices/polylineContextMenuSlice.js index 256c4eafb..9735f7088 100644 --- a/redux/slices/polylineContextMenuSlice.js +++ b/redux/slices/polylineContextMenuSlice.js @@ -7,6 +7,7 @@ const initialState = { forceClose: false, timerStart: null, countdown: 20, + countdownActive: false, // **Neu: Redux merkt, ob der Timer aktiv ist** }; const polylineContextMenuSlice = createSlice({ @@ -19,17 +20,25 @@ const polylineContextMenuSlice = createSlice({ state.forceClose = false; state.timerStart = Date.now(); state.countdown = 20; + state.countdownActive = true; // **Timer aktiv setzen** }, closePolylineContextMenu: (state) => { state.isOpen = false; state.position = null; state.timerStart = null; state.countdown = 0; + state.countdownActive = false; // **Timer stoppen** }, updateCountdown: (state) => { - if (state.timerStart) { + if (state.timerStart && state.countdownActive) { const elapsedTime = (Date.now() - state.timerStart) / 1000; state.countdown = Math.max(20 - elapsedTime, 0); + + if (state.countdown <= 2) { + state.isOpen = false; + state.position = null; + state.countdownActive = false; + } } }, forceCloseContextMenu: (state) => { @@ -38,6 +47,7 @@ const polylineContextMenuSlice = createSlice({ state.forceClose = true; state.timerStart = null; state.countdown = 0; + state.countdownActive = false; }, }, }); diff --git a/utils/polylines/setupPolylines.js b/utils/polylines/setupPolylines.js index fb8505a76..6a13d18d8 100644 --- a/utils/polylines/setupPolylines.js +++ b/utils/polylines/setupPolylines.js @@ -303,21 +303,27 @@ export const setupPolylines = (map, linePositions, lineColors, tooltipContents, polyline.setStyle({ weight: 14 }); const link = `${process.env.NEXT_PUBLIC_BASE_URL}cpl.aspx?ver=35&kue=24&id=${lineData.idLD}`; - console.log("Link der Linie:", link); + // console.log("Link der Linie:", link); }); polyline.on("mouseout", (e) => { polyline.setStyle({ weight: 3 }); - console.log("🚀 Maus hat die Polyline verlassen - Warten auf Klick außerhalb des Menüs."); + // console.log("🚀 Maus hat die Polyline verlassen - Warten auf Klick außerhalb des Menüs."); document.addEventListener("click", function handleOutsideClick(event) { if (!event.target.closest(".leaflet-contextmenu")) { console.log("🛑 Klick außerhalb des Kontextmenüs erkannt - Schließe Menü."); - store.dispatch(closePolylineContextMenu()); - store.dispatch(forceCloseContextMenu()); - if (window.map?.contextmenu) { - window.map.contextmenu.hide(); + try { + store.dispatch(closePolylineContextMenu()); + store.dispatch(forceCloseContextMenu()); + + if (window.map?.contextmenu) { + window.map.contextmenu.hide(); + } + } catch (error) { + console.error("❌ Fehler beim Schließen des Kontextmenüs:", error); + window.location.reload(); // **Seite neu laden, wenn ein Fehler auftritt** } document.removeEventListener("click", handleOutsideClick);