feat: GisSystemStatic in Redux integriert
- API-Response für GisSystemStatic in Redux Store gespeichert - Server-IP aus `.env.local` geladen (`NEXT_PUBLIC_API_BASE_URL`) - `idMap` und `idUser` aus URL-Parametern extrahiert - fetchGisSystemStatic angepasst für dynamische Werte - Redux Store aktualisiert und getestet
This commit is contained in:
16
redux/api/fromWebService/fetchGisSystemStatic.js
Normal file
16
redux/api/fromWebService/fetchGisSystemStatic.js
Normal file
@@ -0,0 +1,16 @@
|
||||
// /redux/api/fromWebService/fetchGisSystemStatic.js
|
||||
import { useSearchParams } from "next/navigation"; // Falls du Next.js 13+ nutzt
|
||||
|
||||
export async function fetchGisSystemStatic() {
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const idMap = params.get("idMap") || "12"; // Fallback-Wert 12
|
||||
const idUser = params.get("idUser") || "484"; // Fallback-Wert 484
|
||||
|
||||
const apiBaseUrl = process.env.NEXT_PUBLIC_API_BASE_URL; // Dynamische Server-IP
|
||||
|
||||
const response = await fetch(`${apiBaseUrl}/GisSystemStatic?idMap=${idMap}&idUser=${idUser}`);
|
||||
const data = await response.json();
|
||||
|
||||
console.log("fetchGisSystemStatic API Response:", data); // ✅ Prüfen, ob API Daten liefert
|
||||
return data;
|
||||
}
|
||||
@@ -1,7 +1,32 @@
|
||||
// /redux/slices/webService/gisSystemStaticSlice.js
|
||||
import { atom } from "recoil";
|
||||
import { createSlice, createAsyncThunk } from "@reduxjs/toolkit";
|
||||
import { fetchGisSystemStatic } from "../../api/fromWebService/fetchGisSystemStatic";
|
||||
|
||||
export const gisSystemStaticState = atom({
|
||||
key: "gisSystemStatic", // Eindeutiger Schlüssel (innerhalb des Projekts)
|
||||
default: [], // Standardwert (Anfangszustand)
|
||||
export const fetchGisSystemStaticFromWebService = createAsyncThunk("gisSystemStatic/fetchGisSystemStaticFromWebService", async () => {
|
||||
const response = await fetchGisSystemStatic();
|
||||
return response.Systems || []; // ✅ Hier sicherstellen, dass nur `Systems` gespeichert wird
|
||||
});
|
||||
|
||||
const gisSystemStaticSlice = createSlice({
|
||||
name: "gisSystemStatic",
|
||||
initialState: {
|
||||
data: [], // ✅ Immer ein Array setzen
|
||||
status: "idle",
|
||||
error: null,
|
||||
},
|
||||
reducers: {
|
||||
setGisSystemStatic: (state, action) => {
|
||||
state.data = action.payload.Systems || []; // ✅ Falls `Systems` fehlt, leeres Array setzen
|
||||
},
|
||||
},
|
||||
extraReducers: (builder) => {
|
||||
builder.addCase(fetchGisSystemStaticFromWebService.fulfilled, (state, action) => {
|
||||
state.status = "succeeded";
|
||||
state.data = action.payload; // ✅ Jetzt sollte `data` direkt das `Systems`-Array enthalten
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
export const { setGisSystemStatic } = gisSystemStaticSlice.actions;
|
||||
export default gisSystemStaticSlice.reducer;
|
||||
export const selectGisSystemStatic = (state) => state.gisSystemStatic.data || [];
|
||||
|
||||
@@ -6,6 +6,7 @@ import locationDevicesFromDBReducer from "./slices/db/locationDevicesFromDBSlice
|
||||
import gisStationsStaticDistrictReducer from "./slices/webService/gisStationsStaticDistrictSlice";
|
||||
import gisStationsStatusDistrictReducer from "./slices/webService/gisStationsStatusDistrictSlice";
|
||||
import gisStationsMeasurementsReducer from "./slices/webService/gisStationsMeasurementsSlice";
|
||||
import gisSystemStaticReducer from "./slices/webService/gisSystemStaticSlice";
|
||||
|
||||
export const store = configureStore({
|
||||
reducer: {
|
||||
@@ -16,5 +17,6 @@ export const store = configureStore({
|
||||
gisStationsStaticDistrict: gisStationsStaticDistrictReducer,
|
||||
gisStationsStatusDistrict: gisStationsStatusDistrictReducer,
|
||||
gisStationsMeasurements: gisStationsMeasurementsReducer,
|
||||
gisSystemStatic: gisSystemStaticReducer,
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user