- WebSocket-Trigger implementiert, der `fetchGisStationsStaticDistrictThunk` ausführt. - Trigger-Mechanismus über `useState` (`triggerUpdate`) sorgt für gezielten UI-Re-Render. - Problem gelöst, dass Redux-Store zwar neue Daten enthielt, aber die UI nicht aktualisiert wurde. - MapComponent.js und useDynamicDeviceLayers.js entsprechend angepasst.
47 lines
1.6 KiB
JavaScript
47 lines
1.6 KiB
JavaScript
// redux/slices/webService/gisStationsStaticDistrictSlice.js
|
|
|
|
import { createSlice } from "@reduxjs/toolkit";
|
|
|
|
import { fetchGisStationsStaticDistrictThunk } from "../../thunks/webservice/fetchGisStationsStaticDistrictThunk";
|
|
|
|
const slice = createSlice({
|
|
name: "gisStationsStaticDistrict",
|
|
initialState: {
|
|
data: { Points: [] }, // Daten als Objekt mit Points-Array
|
|
status: "idle",
|
|
error: null,
|
|
},
|
|
reducers: {
|
|
setGisStationsStaticDistrict: (state, action) => {
|
|
// Stelle sicher, dass die Struktur immer gleich bleibt
|
|
if (Array.isArray(action.payload)) {
|
|
state.data = { Points: action.payload };
|
|
} else if (action.payload?.Points) {
|
|
state.data = { Points: action.payload.Points };
|
|
} else {
|
|
state.data = { Points: [] };
|
|
}
|
|
state.status = "succeeded";
|
|
state.lastUpdated = Date.now();
|
|
},
|
|
}, // Ende der reducers
|
|
extraReducers: builder => {
|
|
builder
|
|
.addCase(fetchGisStationsStaticDistrictThunk.pending, state => {
|
|
state.status = "loading";
|
|
})
|
|
.addCase(fetchGisStationsStaticDistrictThunk.fulfilled, (state, action) => {
|
|
state.status = "succeeded";
|
|
state.data = { Points: action.payload }; // kompatibel mit Zugriff .Points
|
|
})
|
|
.addCase(fetchGisStationsStaticDistrictThunk.rejected, (state, action) => {
|
|
state.status = "failed";
|
|
state.error = action.error.message;
|
|
});
|
|
},
|
|
});
|
|
|
|
export const selectGisStationsStaticDistrict = state => state.gisStationsStaticDistrict.data;
|
|
export default slice.reducer;
|
|
export const { setGisStationsStaticDistrict } = slice.actions;
|