fix: Behebt TypeError: Cannot read properties of null (reading 'contextmenu') mit Redux
- Implementiert `store.subscribe()` in `setupPolylines.js`, um das Kontextmenü-Handling über Redux zu steuern. - Ersetzt `useDispatch()` und `useSelector()` durch `store.dispatch()` und `store.getState()` in einer Nicht-React-Datei. - Fügt eine `forceClose`-Action in `polylineContextMenuSlice.js` hinzu, um das Kontextmenü synchron mit `setInterval` zu schließen. - Stellt sicher, dass das Kontextmenü **immer vor Ablauf des 20-Sekunden-Intervalls** geschlossen wird. - Verhindert doppelte Menüinstanzen und sorgt für ein stabiles Verhalten bei wiederholten Interaktionen. ✅ Fix für `TypeError: Cannot read properties of null (reading 'contextmenu')` ✅ **Verhindert Kontextmenü-Fehler beim automatischen Datenupdate** ✅ **Redux-gesteuerte Menüverwaltung für stabilere Performance** ✅ **Kein unerwartetes Offenbleiben oder erneutes Rendern des Menüs mehr**
This commit is contained in:
32
redux/slices/polylineContextMenuSlice.js
Normal file
32
redux/slices/polylineContextMenuSlice.js
Normal file
@@ -0,0 +1,32 @@
|
||||
// redux/slices/polylineContextMenuSlice.js
|
||||
import { createSlice } from "@reduxjs/toolkit";
|
||||
|
||||
const initialState = {
|
||||
isOpen: false,
|
||||
position: null, // Serialisierbarer Wert { lat, lng }
|
||||
forceClose: false, // Neuer State, um das Schließen zu erzwingen
|
||||
};
|
||||
|
||||
const polylineContextMenuSlice = createSlice({
|
||||
name: "polylineContextMenu",
|
||||
initialState,
|
||||
reducers: {
|
||||
openPolylineContextMenu: (state, action) => {
|
||||
state.isOpen = true;
|
||||
state.position = { lat: action.payload.position.lat, lng: action.payload.position.lng };
|
||||
state.forceClose = false; // Beim Öffnen zurücksetzen
|
||||
},
|
||||
closePolylineContextMenu: (state) => {
|
||||
state.isOpen = false;
|
||||
state.position = null;
|
||||
},
|
||||
forceCloseContextMenu: (state) => {
|
||||
state.isOpen = false;
|
||||
state.position = null;
|
||||
state.forceClose = true; // Setzt Flagge, um Schließen zu signalisieren
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const { openPolylineContextMenu, closePolylineContextMenu, forceCloseContextMenu } = polylineContextMenuSlice.actions;
|
||||
export default polylineContextMenuSlice.reducer;
|
||||
@@ -11,6 +11,7 @@ import gisSystemStaticReducer from "./slices/webService/gisSystemStaticSlice";
|
||||
import gisStationsStaticReducer from "./slices/webService/gisStationsStaticSlice";
|
||||
import poiTypesReducer from "./slices/db/poiTypesSlice";
|
||||
import addPoiOnPolylineReducer from "./slices/addPoiOnPolylineSlice";
|
||||
import polylineContextMenuReducer from "./slices/polylineContextMenuSlice";
|
||||
|
||||
export const store = configureStore({
|
||||
reducer: {
|
||||
@@ -25,5 +26,6 @@ export const store = configureStore({
|
||||
gisStationsStatic: gisStationsStaticReducer,
|
||||
poiTypes: poiTypesReducer,
|
||||
addPoiOnPolyline: addPoiOnPolylineReducer,
|
||||
polylineContextMenu: polylineContextMenuReducer,
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user