fix: Sicherstellen, dass globale Variablen für Kabelüberwachungsseite geladen werden

- `loadWindowVariables` in `kabelueberwachung/page.jsx` implementiert, um erforderliche globale Variablen zu laden.
- Probleme beim Neuladen der Seite behoben, bei denen `window`-Variablen undefiniert waren.
- Stabilität der Seite verbessert und sichergestellt, dass Daten nach Neuladen korrekt angezeigt werden.
This commit is contained in:
ISA
2024-10-25 07:12:54 +02:00
parent f085787053
commit 655a86e915

View File

@@ -2,6 +2,7 @@
import React, { useState, useEffect } from "react"; import React, { useState, useEffect } from "react";
import { useRouter } from "next/navigation"; import { useRouter } from "next/navigation";
import Kue705FO from "../../components/modules/Kue705FO"; import Kue705FO from "../../components/modules/Kue705FO";
import { loadWindowVariables } from "../../utils/loadWindowVariables";
function Kabelueberwachung() { function Kabelueberwachung() {
const router = useRouter(); const router = useRouter();
@@ -23,20 +24,24 @@ function Kabelueberwachung() {
// Load the external JavaScript file and fetch the isolation values // Load the external JavaScript file and fetch the isolation values
useEffect(() => { useEffect(() => {
if (window.kueIso && Array.isArray(window.kueIso)) { loadWindowVariables()
setKueIso(window.kueIso); // Store the isolation values from the global variable .then(() => {
} if (window.kueIso && Array.isArray(window.kueIso)) {
setKueIso(window.kueIso);
if (window.kueRes && Array.isArray(window.kueRes)) { }
setSchleifenwiderstand(window.kueRes); // Store the resistance values from the global variable if (window.kueRes && Array.isArray(window.kueRes)) {
} setSchleifenwiderstand(window.kueRes);
}
if (window.kueOnline && Array.isArray(window.kueOnline)) { if (window.kueOnline && Array.isArray(window.kueOnline)) {
setKueOnline(window.kueOnline); // Store the module status from the global variable setKueOnline(window.kueOnline);
} }
if (window.kueID && Array.isArray(window.kueID)) { if (window.kueID && Array.isArray(window.kueID)) {
setKueID(window.kueID); // Store the KUE names from the global variable setKueID(window.kueID);
} }
})
.catch((error) => {
console.error("Fehler beim Laden der Variablen:", error);
});
}, []); }, []);
// Zuerst alle Werte der Arrays speichern // Zuerst alle Werte der Arrays speichern