- 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
36 lines
1.3 KiB
JavaScript
36 lines
1.3 KiB
JavaScript
// /redux/slices/webService/gisStationsStaticDistrictSlice.js
|
|
import { createSlice, createAsyncThunk } from "@reduxjs/toolkit";
|
|
import { fetchGisStationsStaticDistrict } from "../../api/fromWebService/fetchGisStationsStaticDistrict";
|
|
|
|
export const fetchGisStationsStaticDistrictFromWebService = createAsyncThunk("gisStationsStaticDistrict/fetchGisStationsStaticDistrictFromWebService", async () => {
|
|
return fetchGisStationsStaticDistrict();
|
|
});
|
|
|
|
const gisStationsStaticDistrictSlice = createSlice({
|
|
name: "gisStationsStaticDistrict",
|
|
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 selectGisStationsStaticDistrict = (state) => state.gisStationsStaticDistrict.data;
|
|
|
|
export default gisStationsStaticDistrictSlice.reducer;
|