- Recoil-Atom 'gisStationsStaticDistrictState' in ein Redux-Slice umgewandelt. - fetchGisStationsStaticDistrict angepasst, um Redux-Dispatch zu verwenden. - MapComponent.js und DataSheet.js refaktoriert, um Redux zu integrieren. - fetchOptions für API-Anfragen hinzugefügt. - Zentrale Zustandsverwaltung mit Redux sichergestellt.
65 lines
2.4 KiB
JavaScript
65 lines
2.4 KiB
JavaScript
// services/fetchData.js
|
|
import { setGisStationsStaticDistrict } from "../redux/slices/gisStationsStaticDistrictSlice";
|
|
|
|
export const fetchGisStationsStaticDistrict = async (url, dispatch, fetchOptions) => {
|
|
try {
|
|
const response = await fetch(url, fetchOptions);
|
|
const jsonResponse = await response.json();
|
|
if (jsonResponse && jsonResponse.Points) {
|
|
dispatch(setGisStationsStaticDistrict(jsonResponse.Points));
|
|
} else {
|
|
console.error('Erwartete Daten im "Points"-Array nicht gefunden', jsonResponse);
|
|
dispatch(setGisStationsStaticDistrict([]));
|
|
}
|
|
} catch (error) {
|
|
console.error("Fehler beim Laden der Daten: ", error);
|
|
dispatch(setGisStationsStaticDistrict([]));
|
|
}
|
|
};
|
|
export const fetchGisStationsStatusDistrict = async (url, setGisStationsStatusDistrict) => {
|
|
try {
|
|
const response = await fetch(url);
|
|
const jsonResponse = await response.json();
|
|
if (jsonResponse && jsonResponse.Statis) {
|
|
setGisStationsStatusDistrict(jsonResponse.Statis);
|
|
} else {
|
|
console.error('Erwartete Daten im "Statis"-Array nicht gefunden', jsonResponse);
|
|
setGisStationsStatusDistrict([]);
|
|
}
|
|
} catch (error) {
|
|
console.error("Fehler beim Laden der Daten: ", error);
|
|
setGisStationsStatusDistrict([]);
|
|
}
|
|
};
|
|
export const fetchGisStationsMeasurements = async (url, setGisStationsMeasurements) => {
|
|
try {
|
|
const response = await fetch(url);
|
|
const jsonResponse = await response.json();
|
|
if (jsonResponse && jsonResponse.Statis) {
|
|
setGisStationsMeasurements(jsonResponse.Statis);
|
|
} else {
|
|
console.error('Erwartete Daten im "Statis"-Array nicht gefunden', jsonResponse);
|
|
setGisStationsMeasurements([]);
|
|
}
|
|
} catch (error) {
|
|
console.error("Fehler beim Laden der Daten: ", error);
|
|
setGisStationsMeasurements([]);
|
|
}
|
|
};
|
|
export const fetchGisSystemStatic = async (url, setGisSystemStatic, setGisSystemStaticLoaded) => {
|
|
try {
|
|
const response = await fetch(url);
|
|
const jsonResponse = await response.json();
|
|
if (jsonResponse && jsonResponse.Systems) {
|
|
setGisSystemStatic(jsonResponse.Systems);
|
|
setGisSystemStaticLoaded(true);
|
|
} else {
|
|
console.error('Erwartete Daten im "Systems"-Array nicht gefunden', jsonResponse);
|
|
setGisSystemStatic([]);
|
|
}
|
|
} catch (error) {
|
|
console.error("Fehler beim Laden der Daten: ", error);
|
|
setGisSystemStatic([]);
|
|
}
|
|
};
|