- .env-Variable NEXT_PUBLIC_API_PORT_MODE beschrieben - Beispielaufruf und URL-Mapping ergänzt - Pfadstruktur /docs/frontend/redux/api/... übernommen
59 lines
1.8 KiB
JavaScript
59 lines
1.8 KiB
JavaScript
// /redux/api/fromDB/fetchLocationDevices.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 apiBaseUrl = `${window.location.origin}/talas5/ClientData/WebServiceMap.asmx`;
|
|
|
|
// URL-Parameter aus der aktuellen Browser-URL holen
|
|
const params = new URLSearchParams(window.location.search);
|
|
const idMap = params.get("idMap") || "12"; // Standardwert "12", falls `idMap` nicht existiert
|
|
|
|
const url = `${apiBaseUrl}/GisStationsStatic?idMap=${idMap}`;
|
|
console.log("📡 API Request URL:", 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;
|