diff --git a/hooks/useLineData.js b/hooks/useLineData.js
index 0d95b4919..daf3edaca 100644
--- a/hooks/useLineData.js
+++ b/hooks/useLineData.js
@@ -11,97 +11,84 @@ const useLineData = (webserviceGisLinesStatusUrl, setLineStatusData) => {
const [tooltipContents, setTooltipContents] = useState({});
useEffect(() => {
+ let isCancelled = false; // Flag to cancel ongoing operations if component unmounts
+
const fetchData = async () => {
try {
- console.log("Daten werden abgerufen...");
- const response1 = await fetch(webserviceGisLinesStatusUrl); // original
- //const response1 = await fetch(`${SERVER_URL}:3000/api/talas_v5_DB/gisLines/webserviceGisLinesStatusUrlMock`); //von original kopiert
+ console.log("Fetching data...");
+ const response1 = await fetch(webserviceGisLinesStatusUrl);
const data1 = await response1.json();
- //console.log("Daten empfangen data1:", data1);
+
const response2 = await fetch(`${SERVER_URL}:3000/api/talas_v5_DB/gisLines/readGisLines`);
- //const response2 = await fetch(`${SERVER_URL}:3000/api/talas_v5_DB/gisLines/readGisLinesMock`);
const data2 = await response2.json();
- //console.log("Daten empfangen data2:", data2);
+
const response3 = await fetch(`${SERVER_URL}:3000/api/talas_v5_DB/device/getAllStationsNames`);
- //const response3 = await fetch(`${SERVER_URL}:3000/api/talas_v5_DB/device/getAllStationsNamesMock`);
const namesData = await response3.json();
- //console.log("Daten empfangen namesData:", namesData);
- const colorsByModule = {};
- const newTooltipContents = {};
- const valueMap = {};
+ if (!isCancelled) {
+ const colorsByModule = {};
+ const newTooltipContents = {};
+ const valueMap = {};
- // Logik zur Gruppierung der Daten
- logGroupedData(data1.Statis);
+ logGroupedData(data1.Statis);
- // Sortiere die Meldungen nach Level, damit die höchste Priorität (kleinster Level) zuerst kommt
- const sortedStatis = [...data1.Statis].sort((a, b) => a.Level - b.Level);
- //console.log("Sortierte Daten:", sortedStatis);
+ const sortedStatis = [...data1.Statis].sort((a, b) => a.Level - b.Level);
- // Filtere Objekte mit gleichem IdLD und Modul, und Level > 0, und entferne die Objekte mit dem höchsten Level
- const filteredStatis = [];
- const seenKeys = new Set();
+ const filteredStatis = [];
+ const seenKeys = new Set();
- sortedStatis.forEach((statis) => {
- const key = `${statis.IdLD}-${statis.Modul}`;
+ sortedStatis.forEach((statis) => {
+ const key = `${statis.IdLD}-${statis.Modul}`;
- if (statis.Level > 0) {
- if (!seenKeys.has(key)) {
- seenKeys.add(key);
- filteredStatis.push(statis); // Behalte das Objekt mit dem niedrigsten Level (höchste Priorität)
+ if (statis.Level > 0) {
+ if (!seenKeys.has(key)) {
+ seenKeys.add(key);
+ filteredStatis.push(statis);
+ }
+ } else {
+ filteredStatis.push(statis);
}
- } else {
- // Für Level -1 oder nicht relevante Meldungen einfach hinzufügen
- filteredStatis.push(statis);
- }
- });
+ });
- //console.log("Gefilterte Daten (Objekte mit höchstem Level entfernt):", filteredStatis);
-
- filteredStatis.forEach((statis) => {
- const key = `${statis.IdLD}-${statis.Modul}`;
- if (!valueMap[key]) {
- valueMap[key] = {
- messages: [],
- messwert: undefined,
- schleifenwert: undefined,
- };
- }
-
- // Sammle Messwert und Schleifenwert
- if (statis.DpName.endsWith("_Messwert") && statis.Value !== "True" && !valueMap[key].messwert) {
- valueMap[key].messwert = statis.Value;
- }
- if (statis.DpName.endsWith("_Schleifenwert") && !valueMap[key].schleifenwert) {
- valueMap[key].schleifenwert = statis.Value;
- }
- if (statis.Message && statis.Message !== "?") {
- valueMap[key].messages.push(statis.Message);
- }
- });
-
- // Jetzt durch alle Prioritätslevel gehen und die Farben sowie Meldungen korrekt setzen
- filteredStatis.forEach((statis) => {
- const key = `${statis.IdLD}-${statis.Modul}`;
- const matchingLine = data2.find((item) => item.idLD === statis.IdLD && item.idModul === statis.Modul);
-
- if (matchingLine) {
- const prioColor = statis.PrioColor === "#ffffff" ? "green" : statis.PrioColor;
- const values = valueMap[key];
-
- if (!values) {
- console.error(`Keine Werte gefunden für Key: ${key}`);
- return;
+ filteredStatis.forEach((statis) => {
+ const key = `${statis.IdLD}-${statis.Modul}`;
+ if (!valueMap[key]) {
+ valueMap[key] = {
+ messages: [],
+ messwert: undefined,
+ schleifenwert: undefined,
+ };
}
- // Nachrichtenanzeige
- const messageDisplay = values.messages.map((msg) => (msg ? `${msg}
` : "")).join("");
- const prioNameDisplay = statis.PrioName && statis.PrioName !== "?" ? `(${statis.PrioName})` : "";
+ if (statis.DpName.endsWith("_Messwert") && statis.Value !== "True" && !valueMap[key].messwert) {
+ valueMap[key].messwert = statis.Value;
+ }
+ if (statis.DpName.endsWith("_Schleifenwert") && !valueMap[key].schleifenwert) {
+ valueMap[key].schleifenwert = statis.Value;
+ }
+ if (statis.Message && statis.Message !== "?") {
+ valueMap[key].messages.push(statis.Message);
+ }
+ });
+
+ filteredStatis.forEach((statis) => {
+ const key = `${statis.IdLD}-${statis.Modul}`;
+ const matchingLine = data2.find((item) => item.idLD === statis.IdLD && item.idModul === statis.Modul);
+
+ if (matchingLine) {
+ const prioColor = statis.PrioColor === "#ffffff" ? "green" : statis.PrioColor;
+ const values = valueMap[key];
+
+ if (!values) {
+ console.error(`Keine Werte gefunden für Key: ${key}`);
+ return;
+ }
+
+ const messageDisplay = values.messages.map((msg) => (msg ? `${msg}
` : "")).join("");
+ const prioNameDisplay = statis.PrioName && statis.PrioName !== "?" ? `(${statis.PrioName})` : "";
+
+ colorsByModule[key] = prioColor;
- // Setze die Farbe und Tooltip für jede Linie (für alle Prioritätslevel)
- colorsByModule[key] = prioColor;
- // Überprüfe, ob ModulTyp den Text "705-FO" enthält
- if (statis.ModulTyp && statis.ModulTyp.includes("705-FO")) {
newTooltipContents[key] = `