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:
@@ -49,6 +49,7 @@ import { useFetchPriorityConfig } from "../hooks/useFetchPriorityConfig";
|
|||||||
import { useUpdateGmaData } from "../hooks/useUpdateGmaData";
|
import { useUpdateGmaData } from "../hooks/useUpdateGmaData";
|
||||||
import { useDynamicMarkerLayers } from "../hooks/useDynamicMarkerLayers";
|
import { useDynamicMarkerLayers } from "../hooks/useDynamicMarkerLayers";
|
||||||
import { useFetchUserRights } from "../hooks/useFetchUserRights";
|
import { useFetchUserRights } from "../hooks/useFetchUserRights";
|
||||||
|
import { useFetchWebServiceMap } from "../hooks/useFetchWebServiceMap";
|
||||||
//--------------------------------------------
|
//--------------------------------------------
|
||||||
import { currentPoiState } from "../redux/slices/currentPoiSlice.js";
|
import { currentPoiState } from "../redux/slices/currentPoiSlice.js";
|
||||||
import { selectGisStationsStaticDistrict, setGisStationsStaticDistrict } from "../redux/slices/gisStationsStaticDistrictSlice";
|
import { selectGisStationsStaticDistrict, setGisStationsStaticDistrict } from "../redux/slices/gisStationsStaticDistrictSlice";
|
||||||
@@ -180,11 +181,7 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
|
|||||||
});
|
});
|
||||||
const [polylineEventsDisabled, setPolylineEventsDisabled] = useRecoilState(polylineEventsDisabledState); // Recoil State
|
const [polylineEventsDisabled, setPolylineEventsDisabled] = useRecoilState(polylineEventsDisabledState); // Recoil State
|
||||||
|
|
||||||
//---------------------------------------------------------------
|
//---------------------------------------------------------------############################################
|
||||||
|
|
||||||
/* useEffect(() => {
|
|
||||||
fetchGisStatusStations(12, 484); // Beispielaufruf mit idMap = 10 und idUser = 484
|
|
||||||
}, []); */
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const params = new URL(window.location.href).searchParams;
|
const params = new URL(window.location.href).searchParams;
|
||||||
@@ -192,20 +189,6 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
|
|||||||
setUserId(params.get("u"));
|
setUserId(params.get("u"));
|
||||||
}, [setMapId, setUserId]);
|
}, [setMapId, setUserId]);
|
||||||
|
|
||||||
/* useEffect(() => {
|
|
||||||
if (map && poiLayerRef.current && isPoiTypLoaded && !menuItemAdded && isRightsLoaded) {
|
|
||||||
//console.log("Überprüfung der Berechtigung vor addItemsToMapContextMenu: ", hasRights);
|
|
||||||
addItemsToMapContextMenu(hasRights);
|
|
||||||
}
|
|
||||||
}, [
|
|
||||||
map,
|
|
||||||
poiLayerRef,
|
|
||||||
isPoiTypLoaded,
|
|
||||||
menuItemAdded, // Hinzufügen zu den Abhängigkeiten, um den Effekt korrekt zu steuern
|
|
||||||
hasRights, // Sicherstellen, dass hasRights berücksichtigt wird
|
|
||||||
isRightsLoaded, // Überprüfung, ob die Rechte geladen sind
|
|
||||||
]); */
|
|
||||||
|
|
||||||
//---------------------------------------------------------------
|
//---------------------------------------------------------------
|
||||||
// Benutzerrechte abrufen und setzen
|
// Benutzerrechte abrufen und setzen
|
||||||
useFetchUserRights(setUserRights, setIsRightsLoaded, setHasRights);
|
useFetchUserRights(setUserRights, setIsRightsLoaded, setHasRights);
|
||||||
@@ -220,7 +203,7 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
|
|||||||
oms,
|
oms,
|
||||||
mapLayersVisibility.GMA // Übergebe die Sichtbarkeitsbedingung als Parameter
|
mapLayersVisibility.GMA // Übergebe die Sichtbarkeitsbedingung als Parameter
|
||||||
);
|
);
|
||||||
|
//---------------------------------------------------------------
|
||||||
/* useSmsfunkmodemMarkersLayer(
|
/* useSmsfunkmodemMarkersLayer(
|
||||||
map,
|
map,
|
||||||
oms,
|
oms,
|
||||||
@@ -228,51 +211,18 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
|
|||||||
priorityConfig,
|
priorityConfig,
|
||||||
mapLayersVisibility.SMSFunkmodem // Sichtbarkeitsstatus aus dem State
|
mapLayersVisibility.SMSFunkmodem // Sichtbarkeitsstatus aus dem State
|
||||||
); */
|
); */
|
||||||
|
//---------------------------------------------------------------
|
||||||
useEffect(() => {
|
useFetchWebServiceMap(
|
||||||
const fetchWebServiceMap = async () => {
|
dispatch,
|
||||||
try {
|
mapGisStationsStaticDistrictUrl,
|
||||||
// Zähler für externe API-Aufrufe in localStorage speichern
|
mapGisStationsStatusDistrictUrl,
|
||||||
let requestCount = localStorage.getItem("fetchWebServiceMap") || 0;
|
mapGisStationsMeasurementsUrl,
|
||||||
requestCount = parseInt(requestCount, 10);
|
mapGisSystemStaticUrl,
|
||||||
|
setGisStationsStatusDistrict,
|
||||||
const fetchOptions = {
|
setGisStationsMeasurements,
|
||||||
method: "GET",
|
setGisSystemStatic,
|
||||||
headers: {
|
setGisSystemStaticLoaded
|
||||||
Connection: "close", // Keep-Alive-Header hinzufügen
|
);
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
// Fetch GIS Stations Static District
|
|
||||||
await fetchGisStationsStaticDistrict(mapGisStationsStaticDistrictUrl, dispatch, fetchOptions);
|
|
||||||
requestCount++; // Zähler erhöhen
|
|
||||||
localStorage.setItem("fetchWebServiceMap", requestCount);
|
|
||||||
//console.log(`fetchWebServiceMap in MapComponent wurde ${requestCount} Mal aufgerufen.`);
|
|
||||||
|
|
||||||
// Fetch GIS Stations Status District
|
|
||||||
await fetchGisStationsStatusDistrict(mapGisStationsStatusDistrictUrl, setGisStationsStatusDistrict, fetchOptions);
|
|
||||||
requestCount++; // Zähler erhöhen
|
|
||||||
localStorage.setItem("fetchWebServiceMap", requestCount);
|
|
||||||
//console.log(`fetchWebServiceMap in MapComponent wurde ${requestCount} Mal aufgerufen.`);
|
|
||||||
|
|
||||||
// Fetch GIS Stations Measurements
|
|
||||||
await fetchGisStationsMeasurements(mapGisStationsMeasurementsUrl, setGisStationsMeasurements, fetchOptions);
|
|
||||||
requestCount++; // Zähler erhöhen
|
|
||||||
localStorage.setItem("fetchWebServiceMap", requestCount);
|
|
||||||
//console.log(`fetchWebServiceMap in MapComponent wurde ${requestCount} Mal aufgerufen.`);
|
|
||||||
|
|
||||||
// Fetch GIS System Static
|
|
||||||
await fetchGisSystemStatic(mapGisSystemStaticUrl, setGisSystemStatic, setGisSystemStaticLoaded, fetchOptions);
|
|
||||||
requestCount++; // Zähler erhöhen
|
|
||||||
localStorage.setItem("fetchWebServiceMap", requestCount);
|
|
||||||
//console.log(`fetchWebServiceMap in MapComponent wurde ${requestCount} Mal aufgerufen.`);
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Error fetching data:", error);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
fetchWebServiceMap();
|
|
||||||
}, [dispatch, mapGisStationsStaticDistrictUrl]);
|
|
||||||
|
|
||||||
//--------------------------------------------------------
|
//--------------------------------------------------------
|
||||||
useDrawLines(setLinePositions); // Linien auf die Karte zeichnen
|
useDrawLines(setLinePositions); // Linien auf die Karte zeichnen
|
||||||
|
|||||||
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