refactor: GIS-Redux-Slices reduziert auf 4 (statt 5) – veraltete Slices und Thunks entfernt, Code bereinigt
This commit is contained in:
@@ -1,32 +1,33 @@
|
||||
// /redux/slices/webService/gisSystemStaticSlice.js
|
||||
|
||||
import { createSlice, createAsyncThunk } from "@reduxjs/toolkit";
|
||||
import { fetchGisSystemStatic } from "../../api/fromWebService/fetchGisSystemStatic";
|
||||
import { fetchGisSystemStaticService } from "../../../services/webservice/fetchGisSystemStaticService";
|
||||
|
||||
export const fetchGisSystemStaticFromWebService = createAsyncThunk("gisSystemStatic/fetchGisSystemStaticFromWebService", async () => {
|
||||
const response = await fetchGisSystemStatic();
|
||||
return response.Systems || []; // ✅ Hier sicherstellen, dass nur `Systems` gespeichert wird
|
||||
});
|
||||
import { fetchGisSystemStaticThunk } from "../../thunks/fetchGisSystemStaticThunk";
|
||||
|
||||
const gisSystemStaticSlice = createSlice({
|
||||
const slice = createSlice({
|
||||
name: "gisSystemStatic",
|
||||
initialState: {
|
||||
data: [], // ✅ Immer ein Array setzen
|
||||
data: [],
|
||||
status: "idle",
|
||||
error: null,
|
||||
},
|
||||
reducers: {
|
||||
setGisSystemStatic: (state, action) => {
|
||||
state.data = action.payload.Systems || []; // ✅ Falls `Systems` fehlt, leeres Array setzen
|
||||
},
|
||||
},
|
||||
reducers: {},
|
||||
extraReducers: (builder) => {
|
||||
builder.addCase(fetchGisSystemStaticFromWebService.fulfilled, (state, action) => {
|
||||
state.status = "succeeded";
|
||||
state.data = action.payload; // ✅ Jetzt sollte `data` direkt das `Systems`-Array enthalten
|
||||
});
|
||||
builder
|
||||
.addCase(fetchGisSystemStaticThunk.pending, (state) => {
|
||||
state.status = "loading";
|
||||
})
|
||||
.addCase(fetchGisSystemStaticThunk.fulfilled, (state, action) => {
|
||||
state.status = "succeeded";
|
||||
state.data = action.payload;
|
||||
})
|
||||
.addCase(fetchGisSystemStaticThunk.rejected, (state, action) => {
|
||||
state.status = "failed";
|
||||
state.error = action.error.message;
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
export const { setGisSystemStatic } = gisSystemStaticSlice.actions;
|
||||
export default gisSystemStaticSlice.reducer;
|
||||
export const selectGisSystemStatic = (state) => state.gisSystemStatic.data || [];
|
||||
export default slice.reducer;
|
||||
export const selectGisSystemStatic = (state) => state.gisSystemStatic.data;
|
||||
|
||||
Reference in New Issue
Block a user