// /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;