fix: wenn ftech Breiche fehler soll die Seite im Browser nicht neu laden
feat:von anderen PC /Test PC zugreifen, Laptop als Server
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
// hooks/useLineData.js
|
||||
// hooks/useLineData.js //fix v1.0.8.1
|
||||
import { useEffect, useState } from "react";
|
||||
import { toast } from "react-toastify";
|
||||
import { SERVER_URL } from "../config/urls";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
|
||||
@@ -15,20 +16,25 @@ const useLineData = (webserviceGisLinesStatusUrl, setLineStatusData) => {
|
||||
const fetchData = async () => {
|
||||
try {
|
||||
const response1 = await fetch(webserviceGisLinesStatusUrl);
|
||||
if (!response1.ok) throw new Error("Fehler bei GIS-Linienstatus");
|
||||
|
||||
const data1 = await response1.json();
|
||||
|
||||
const response2 = await fetch(`${SERVER_URL}:3000/api/talas_v5_DB/gisLines/readGisLines`);
|
||||
if (!response2.ok) throw new Error("Fehler beim Abrufen der GIS-Linien");
|
||||
|
||||
const data2 = await response2.json();
|
||||
|
||||
if (!Array.isArray(data2)) {
|
||||
console.warn("gis_lines Daten sind nicht in der erwarteten Form. Wird ignoriert.");
|
||||
return;
|
||||
}
|
||||
|
||||
const response3 = await fetch(`${SERVER_URL}:3000/api/talas_v5_DB/device/getAllStationsNames`);
|
||||
if (!response3.ok) throw new Error("Fehler beim Abrufen der Stationsnamen");
|
||||
|
||||
const namesData = await response3.json();
|
||||
|
||||
if (!isCancelled) {
|
||||
if (!data1.Statis || data1.Statis.length === 0) {
|
||||
toast.warn("Keine Linienstatus-Daten verfügbar!", { position: "top-center", autoClose: 5000 });
|
||||
setLineStatusData([]);
|
||||
return;
|
||||
}
|
||||
|
||||
const colorsByModule = {};
|
||||
const newTooltipContents = {};
|
||||
const valueMap = {};
|
||||
@@ -70,8 +76,6 @@ const useLineData = (webserviceGisLinesStatusUrl, setLineStatusData) => {
|
||||
|
||||
const messageDisplay = values.messages.map((msg) => `<span class="inline-block text-gray-800"><span class="inline-block w-2 h-2 rounded-full mr-2" style="background-color: ${msg.prioColor};"></span>${msg.message}</span><br>`).join("");
|
||||
|
||||
const prioNameDisplay = statis.PrioName && statis.PrioName !== "?" ? `(${statis.PrioName})` : "";
|
||||
|
||||
colorsByModule[key] = values.messages.length > 0 ? values.messages[0].prioColor : "green";
|
||||
|
||||
newTooltipContents[key] = `
|
||||
@@ -98,21 +102,11 @@ const useLineData = (webserviceGisLinesStatusUrl, setLineStatusData) => {
|
||||
setLineColors(colorsByModule);
|
||||
setTooltipContents(newTooltipContents);
|
||||
setLineStatusData(data1.Statis);
|
||||
|
||||
// Setze den Timeout für die Kontextmenü-Überwachung
|
||||
const countdownDuration = 30000; // 30 Sekunden für den Countdown
|
||||
setTimeout(() => {
|
||||
console.log("Setting contextMenuExpired to true");
|
||||
localStorage.setItem("contextMenuExpired", "true");
|
||||
}, countdownDuration);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Fehler beim Abrufen der Daten:", error);
|
||||
try {
|
||||
window.location.reload();
|
||||
} catch (reloadError) {
|
||||
console.error("Fehler beim Neuladen der Seite:", reloadError);
|
||||
}
|
||||
//console.error("Fehler beim Abrufen der Daten in useLineData.js:", error);
|
||||
// toast.error("Fehler beim Abrufen der Linienstatus-Daten!", { position: "top-center", autoClose: 5000 });
|
||||
console.warn("Fehler beim Abrufen der Linienstatus-Daten in useLineData.js ");
|
||||
}
|
||||
};
|
||||
|
||||
@@ -128,7 +122,7 @@ const useLineData = (webserviceGisLinesStatusUrl, setLineStatusData) => {
|
||||
|
||||
return () => {
|
||||
isCancelled = true;
|
||||
localStorage.removeItem("contextMenuExpired"); // Flagge entfernen, wenn das Hook unmounted wird
|
||||
localStorage.removeItem("contextMenuExpired");
|
||||
};
|
||||
}, [webserviceGisLinesStatusUrl, setLineStatusData]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user