refactor: GIS-Redux-Slices reduziert auf 4 (statt 5) – veraltete Slices und Thunks entfernt, Code bereinigt
This commit is contained in:
@@ -1,12 +1,9 @@
|
||||
// /redux/slices/webService/gisStationsMeasurementsSlice.js
|
||||
import { createSlice, createAsyncThunk } from "@reduxjs/toolkit";
|
||||
import { fetchGisStationsMeasurements } from "../../api/fromWebService/fetchGisStationsMeasurements";
|
||||
|
||||
export const fetchGisStationsMeasurementsFromWebService = createAsyncThunk("gisStationsMeasurements/fetchGisStationsMeasurementsFromWebService", async () => {
|
||||
return fetchGisStationsMeasurements();
|
||||
});
|
||||
import { createSlice } from "@reduxjs/toolkit";
|
||||
import { fetchGisStationsMeasurementsThunk } from "../../thunks/fetchGisStationsMeasurementsThunk";
|
||||
|
||||
const gisStationsMeasurementsSlice = createSlice({
|
||||
const slice = createSlice({
|
||||
name: "gisStationsMeasurements",
|
||||
initialState: {
|
||||
data: [],
|
||||
@@ -16,20 +13,19 @@ const gisStationsMeasurementsSlice = createSlice({
|
||||
reducers: {},
|
||||
extraReducers: (builder) => {
|
||||
builder
|
||||
.addCase(fetchGisStationsMeasurementsFromWebService.pending, (state) => {
|
||||
.addCase(fetchGisStationsMeasurementsThunk.pending, (state) => {
|
||||
state.status = "loading";
|
||||
})
|
||||
.addCase(fetchGisStationsMeasurementsFromWebService.fulfilled, (state, action) => {
|
||||
.addCase(fetchGisStationsMeasurementsThunk.fulfilled, (state, action) => {
|
||||
state.status = "succeeded";
|
||||
state.data = action.payload;
|
||||
})
|
||||
.addCase(fetchGisStationsMeasurementsFromWebService.rejected, (state, action) => {
|
||||
.addCase(fetchGisStationsMeasurementsThunk.rejected, (state, action) => {
|
||||
state.status = "failed";
|
||||
state.error = action.error.message;
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
export default slice.reducer;
|
||||
export const selectGisStationsMeasurements = (state) => state.gisStationsMeasurements.data;
|
||||
|
||||
export default gisStationsMeasurementsSlice.reducer;
|
||||
|
||||
@@ -1,29 +1,28 @@
|
||||
// /redux/slices/webService/gisStationsStaticDistrictSlice.js
|
||||
// redux/slices/webService/gisStationsStaticDistrictSlice.js
|
||||
|
||||
import { createSlice, createAsyncThunk } from "@reduxjs/toolkit";
|
||||
import { fetchGisStationsStaticDistrict } from "../../api/fromWebService/fetchGisStationsStaticDistrict";
|
||||
import { fetchGisStationsStaticDistrictService } from "../../../services/webservice/fetchGisStationsStaticDistrictService";
|
||||
|
||||
export const fetchGisStationsStaticDistrictFromWebService = createAsyncThunk("gisStationsStaticDistrict/fetchGisStationsStaticDistrictFromWebService", async () => {
|
||||
return fetchGisStationsStaticDistrict();
|
||||
});
|
||||
import { fetchGisStationsStaticDistrictThunk } from "../../thunks/fetchGisStationsStaticDistrictThunk";
|
||||
|
||||
const gisStationsStaticDistrictSlice = createSlice({
|
||||
const slice = createSlice({
|
||||
name: "gisStationsStaticDistrict",
|
||||
initialState: {
|
||||
data: [],
|
||||
data: { Points: [] }, // Daten als Objekt mit Points-Array
|
||||
status: "idle",
|
||||
error: null,
|
||||
},
|
||||
reducers: {},
|
||||
extraReducers: (builder) => {
|
||||
builder
|
||||
.addCase(fetchGisStationsStaticDistrictFromWebService.pending, (state) => {
|
||||
.addCase(fetchGisStationsStaticDistrictThunk.pending, (state) => {
|
||||
state.status = "loading";
|
||||
})
|
||||
.addCase(fetchGisStationsStaticDistrictFromWebService.fulfilled, (state, action) => {
|
||||
.addCase(fetchGisStationsStaticDistrictThunk.fulfilled, (state, action) => {
|
||||
state.status = "succeeded";
|
||||
state.data = action.payload;
|
||||
state.data = { Points: action.payload }; // kompatibel mit Zugriff .Points
|
||||
})
|
||||
.addCase(fetchGisStationsStaticDistrictFromWebService.rejected, (state, action) => {
|
||||
.addCase(fetchGisStationsStaticDistrictThunk.rejected, (state, action) => {
|
||||
state.status = "failed";
|
||||
state.error = action.error.message;
|
||||
});
|
||||
@@ -31,5 +30,4 @@ const gisStationsStaticDistrictSlice = createSlice({
|
||||
});
|
||||
|
||||
export const selectGisStationsStaticDistrict = (state) => state.gisStationsStaticDistrict.data;
|
||||
|
||||
export default gisStationsStaticDistrictSlice.reducer;
|
||||
export default slice.reducer;
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
// /redux/slices/webService/gisStationsStaticSlice.js
|
||||
// das ist für Datasheet dropdownmenu Bereiche/Area-Name
|
||||
import { createSlice, createAsyncThunk } from "@reduxjs/toolkit";
|
||||
|
||||
// API-Fetch-Funktion für GIS Stations Static mit dynamischem URL-Parameter
|
||||
export const fetchGisStationsStatic = createAsyncThunk("gisStationsStatic/fetchGisStationsStatic", async (_, { rejectWithValue }) => {
|
||||
try {
|
||||
const host = window.location.hostname;
|
||||
const protocol = window.location.protocol;
|
||||
const apiPort = 80; // Oder aus einer Umgebungsvariable
|
||||
const apiBaseUrl = `${protocol}//${host}:${apiPort}/talas5/ClientData/WebServiceMap.asmx`;
|
||||
|
||||
// URL-Parameter aus der aktuellen Browser-URL holen
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const idMap = params.get("m");
|
||||
|
||||
const url = `${apiBaseUrl}/GisStationsStatic?idMap=${idMap}`;
|
||||
console.log("📡 API Request URL in redux slice:", url);
|
||||
|
||||
const response = await fetch(url);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error("GisStationsStatic konnte nicht geladen werden");
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
return data;
|
||||
} catch (error) {
|
||||
return rejectWithValue(error.message);
|
||||
}
|
||||
});
|
||||
|
||||
// Redux-Slice
|
||||
const gisStationsStaticSlice = createSlice({
|
||||
name: "gisStationsStatic",
|
||||
initialState: {
|
||||
data: null,
|
||||
status: "idle",
|
||||
error: null,
|
||||
},
|
||||
reducers: {},
|
||||
extraReducers: (builder) => {
|
||||
builder
|
||||
.addCase(fetchGisStationsStatic.pending, (state) => {
|
||||
state.status = "loading";
|
||||
})
|
||||
.addCase(fetchGisStationsStatic.fulfilled, (state, action) => {
|
||||
state.status = "succeeded";
|
||||
state.data = action.payload;
|
||||
})
|
||||
.addCase(fetchGisStationsStatic.rejected, (state, action) => {
|
||||
state.status = "failed";
|
||||
state.error = action.payload;
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
// Selector-Funktion
|
||||
export const selectGisStationsStatic = (state) => state.gisStationsStatic.data;
|
||||
|
||||
export default gisStationsStaticSlice.reducer;
|
||||
@@ -1,12 +1,11 @@
|
||||
// /redux/slices/webService/gisStationsStatusDistrictSlice.js
|
||||
|
||||
import { createSlice, createAsyncThunk } from "@reduxjs/toolkit";
|
||||
import { fetchGisStationsStatusDistrict } from "../../api/fromWebService/fetchGisStationsStatusDistrict";
|
||||
import { fetchGisStationsStatusDistrictService } from "../../../services/webservice/fetchGisStationsStatusDistrictService";
|
||||
|
||||
export const fetchGisStationsStatusDistrictFromWebService = createAsyncThunk("gisStationsStatusDistrict/fetchGisStationsStatusDistrictFromWebService", async () => {
|
||||
return fetchGisStationsStatusDistrict();
|
||||
});
|
||||
import { fetchGisStationsStatusDistrictThunk } from "../../thunks/fetchGisStationsStatusDistrictThunk";
|
||||
|
||||
const gisStationsStatusDistrictSlice = createSlice({
|
||||
const slice = createSlice({
|
||||
name: "gisStationsStatusDistrict",
|
||||
initialState: {
|
||||
data: [],
|
||||
@@ -16,20 +15,19 @@ const gisStationsStatusDistrictSlice = createSlice({
|
||||
reducers: {},
|
||||
extraReducers: (builder) => {
|
||||
builder
|
||||
.addCase(fetchGisStationsStatusDistrictFromWebService.pending, (state) => {
|
||||
.addCase(fetchGisStationsStatusDistrictThunk.pending, (state) => {
|
||||
state.status = "loading";
|
||||
})
|
||||
.addCase(fetchGisStationsStatusDistrictFromWebService.fulfilled, (state, action) => {
|
||||
.addCase(fetchGisStationsStatusDistrictThunk.fulfilled, (state, action) => {
|
||||
state.status = "succeeded";
|
||||
state.data = action.payload;
|
||||
})
|
||||
.addCase(fetchGisStationsStatusDistrictFromWebService.rejected, (state, action) => {
|
||||
.addCase(fetchGisStationsStatusDistrictThunk.rejected, (state, action) => {
|
||||
state.status = "failed";
|
||||
state.error = action.error.message;
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
export default slice.reducer;
|
||||
export const selectGisStationsStatusDistrict = (state) => state.gisStationsStatusDistrict.data;
|
||||
|
||||
export default gisStationsStatusDistrictSlice.reducer;
|
||||
|
||||
@@ -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