feat: Fetch-Logik für Webservice-Daten in useFetchWebServiceMap Hook ausgelagert
- Fetch-Logik für GIS-Daten aus MapComponent.js ausgelagert. - Neuer Hook: useFetchWebServiceMap im hooks-Verzeichnis hinzugefügt. - Modularisierung und Wiederverwendbarkeit verbessert.
This commit is contained in:
87
hooks/useFetchWebServiceMap.js
Normal file
87
hooks/useFetchWebServiceMap.js
Normal file
@@ -0,0 +1,87 @@
|
||||
import { useEffect } from "react";
|
||||
import {
|
||||
fetchGisStationsStaticDistrict,
|
||||
fetchGisStationsStatusDistrict,
|
||||
fetchGisStationsMeasurements,
|
||||
fetchGisSystemStatic,
|
||||
} from "../services/fetchData";
|
||||
|
||||
export const useFetchWebServiceMap = (
|
||||
dispatch,
|
||||
mapGisStationsStaticDistrictUrl,
|
||||
mapGisStationsStatusDistrictUrl,
|
||||
mapGisStationsMeasurementsUrl,
|
||||
mapGisSystemStaticUrl,
|
||||
setGisStationsStatusDistrict,
|
||||
setGisStationsMeasurements,
|
||||
setGisSystemStatic,
|
||||
setGisSystemStaticLoaded
|
||||
) => {
|
||||
useEffect(() => {
|
||||
const fetchWebServiceMap = async () => {
|
||||
try {
|
||||
// Zähler für externe API-Aufrufe in localStorage speichern
|
||||
let requestCount = localStorage.getItem("fetchWebServiceMap") || 0;
|
||||
requestCount = parseInt(requestCount, 10);
|
||||
|
||||
const fetchOptions = {
|
||||
method: "GET",
|
||||
headers: {
|
||||
Connection: "close",
|
||||
},
|
||||
};
|
||||
|
||||
// Fetch GIS Stations Static District
|
||||
await fetchGisStationsStaticDistrict(
|
||||
mapGisStationsStaticDistrictUrl,
|
||||
dispatch,
|
||||
fetchOptions
|
||||
);
|
||||
requestCount++;
|
||||
localStorage.setItem("fetchWebServiceMap", requestCount);
|
||||
|
||||
// Fetch GIS Stations Status District
|
||||
await fetchGisStationsStatusDistrict(
|
||||
mapGisStationsStatusDistrictUrl,
|
||||
setGisStationsStatusDistrict,
|
||||
fetchOptions
|
||||
);
|
||||
requestCount++;
|
||||
localStorage.setItem("fetchWebServiceMap", requestCount);
|
||||
|
||||
// Fetch GIS Stations Measurements
|
||||
await fetchGisStationsMeasurements(
|
||||
mapGisStationsMeasurementsUrl,
|
||||
setGisStationsMeasurements,
|
||||
fetchOptions
|
||||
);
|
||||
requestCount++;
|
||||
localStorage.setItem("fetchWebServiceMap", requestCount);
|
||||
|
||||
// Fetch GIS System Static
|
||||
await fetchGisSystemStatic(
|
||||
mapGisSystemStaticUrl,
|
||||
setGisSystemStatic,
|
||||
setGisSystemStaticLoaded,
|
||||
fetchOptions
|
||||
);
|
||||
requestCount++;
|
||||
localStorage.setItem("fetchWebServiceMap", requestCount);
|
||||
} catch (error) {
|
||||
console.error("Error fetching data:", error);
|
||||
}
|
||||
};
|
||||
|
||||
fetchWebServiceMap();
|
||||
}, [
|
||||
dispatch,
|
||||
mapGisStationsStaticDistrictUrl,
|
||||
mapGisStationsStatusDistrictUrl,
|
||||
mapGisStationsMeasurementsUrl,
|
||||
mapGisSystemStaticUrl,
|
||||
setGisStationsStatusDistrict,
|
||||
setGisStationsMeasurements,
|
||||
setGisSystemStatic,
|
||||
setGisSystemStaticLoaded,
|
||||
]);
|
||||
};
|
||||
Reference in New Issue
Block a user