feat: GisStationsStaticDistrict in Redux-Store integriert
- WebService-Endpoint für GisStationsStaticDistrict angebunden - Daten beim Start der Anwendung automatisch geladen und in Redux gespeichert - UI (DataSheet) verwendet die Daten direkt aus dem Redux-Store - Fehlerhandling und Initialzustand in Redux-Slice verbessert - Alte lokale Fetch-Logik entfernt, zentrale Datenhaltung über Redux
This commit is contained in:
@@ -1,23 +1,35 @@
|
||||
// /redux/slices/webService/gisStationsStaticDistrictSlice.js
|
||||
import { createSlice } from "@reduxjs/toolkit";
|
||||
import { createSlice, createAsyncThunk } from "@reduxjs/toolkit";
|
||||
import { fetchGisStationsStaticDistrict } from "../../api/fromWebService/fetchGisStationsStaticDistrict";
|
||||
|
||||
const initialState = [];
|
||||
export const fetchGisStationsStaticDistrictFromWebService = createAsyncThunk("gisStationsStaticDistrict/fetchGisStationsStaticDistrictFromWebService", async () => {
|
||||
return fetchGisStationsStaticDistrict();
|
||||
});
|
||||
|
||||
const gisStationsStaticDistrictSlice = createSlice({
|
||||
name: "gisStationsStaticDistrict",
|
||||
initialState,
|
||||
reducers: {
|
||||
setGisStationsStaticDistrict: (state, action) => {
|
||||
return action.payload;
|
||||
},
|
||||
clearGisStationsStaticDistrict: () => {
|
||||
return [];
|
||||
},
|
||||
initialState: {
|
||||
data: [],
|
||||
status: "idle",
|
||||
error: null,
|
||||
},
|
||||
reducers: {},
|
||||
extraReducers: (builder) => {
|
||||
builder
|
||||
.addCase(fetchGisStationsStaticDistrictFromWebService.pending, (state) => {
|
||||
state.status = "loading";
|
||||
})
|
||||
.addCase(fetchGisStationsStaticDistrictFromWebService.fulfilled, (state, action) => {
|
||||
state.status = "succeeded";
|
||||
state.data = action.payload;
|
||||
})
|
||||
.addCase(fetchGisStationsStaticDistrictFromWebService.rejected, (state, action) => {
|
||||
state.status = "failed";
|
||||
state.error = action.error.message;
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
export const { setGisStationsStaticDistrict, clearGisStationsStaticDistrict } = gisStationsStaticDistrictSlice.actions;
|
||||
|
||||
export const selectGisStationsStaticDistrict = (state) => state.gisStationsStaticDistrict;
|
||||
export const selectGisStationsStaticDistrict = (state) => state.gisStationsStaticDistrict.data;
|
||||
|
||||
export default gisStationsStaticDistrictSlice.reducer;
|
||||
|
||||
Reference in New Issue
Block a user