- Fetch-Logik für Linienstatusdaten aus MapComponent.js in einen separaten Hook ausgelagert. - Neuer Hook: useFetchLineStatusData im hooks-Verzeichnis hinzugefügt. - Verbesserung der Modularität und Wiederverwendbarkeit.
36 lines
1.1 KiB
JavaScript
36 lines
1.1 KiB
JavaScript
import { useEffect } from "react";
|
|
|
|
export const useFetchLineStatusData = (
|
|
webserviceGisLinesStatusUrl,
|
|
setLineStatusData,
|
|
setLinesData
|
|
) => {
|
|
useEffect(() => {
|
|
const fetchData = async () => {
|
|
try {
|
|
const response1 = await fetch(webserviceGisLinesStatusUrl);
|
|
const data1 = await response1.json();
|
|
const reversedData = data1.Statis.reverse();
|
|
setLineStatusData(reversedData);
|
|
|
|
const response2 = await fetch("/api/talas_v5_DB/gisLines/readGisLines");
|
|
const data2 = await response2.json();
|
|
|
|
const colorsByModule = {};
|
|
reversedData.forEach((stat) => {
|
|
const matchingLine = data2.find(
|
|
(item) => item.idLD === stat.IdLD && item.idModul === stat.Modul
|
|
);
|
|
if (matchingLine) {
|
|
colorsByModule[matchingLine.idModul] = stat.PrioColor;
|
|
setLinesData(matchingLine);
|
|
}
|
|
});
|
|
} catch (error) {
|
|
console.error("Error fetching data:", error);
|
|
}
|
|
};
|
|
fetchData();
|
|
}, [webserviceGisLinesStatusUrl, setLineStatusData, setLinesData]);
|
|
};
|