useEffect aus einausgaenge.tsx wurde entfernt und durch den useLoadScript-Hook ersetzt.

This commit is contained in:
Ismail Ali
2025-02-18 10:29:28 +01:00
parent d48579fafa
commit 3b482935d5
3 changed files with 8 additions and 51 deletions

View File

@@ -6,5 +6,5 @@
2: Patch oder Hotfix (Bugfixes oder kleine Änderungen).
*/
const webVersion = "1.6.52";
const webVersion = "1.6.53";
export default webVersion;

View File

@@ -2,7 +2,11 @@
import { useEffect, useState } from "react";
export function useLoadScript() {
const [mockData, setMockData] = useState();
const [mockData, setMockData] = useState({
win_de: Array(32).fill(0),
win_counter: Array(32).fill(0),
win_flutter: Array(32).fill(0),
});
const [isLoading, setIsLoading] = useState(true);
useEffect(() => {

View File

@@ -3,15 +3,9 @@ import React, { useState, useEffect } from "react";
import { Icon } from "@iconify/react";
import DigitalOutputs from "../components/main/einausgaenge/DigitalOutputs";
import DigitalInputs from "../components/main/einausgaenge/DigitalInputs";
import { useLoadScript } from "../hooks/useLoadScript";
function EinAusgaenge() {
const [mockData, setMockData] = useState({
win_de: Array(32).fill(0),
win_counter: Array(32).fill(0),
win_flutter: Array(32).fill(0),
});
const [isLoading, setIsLoading] = useState(true);
// Digitale Ausgänge (Hooks müssen immer initialisiert werden)
const [digitalOutputs, setDigitalOutputs] = useState([
{ id: 1, description: "Ausgang1", toggle: true },
@@ -26,48 +20,7 @@ function EinAusgaenge() {
const [isInputModalOpen, setIsInputModalOpen] = useState(false);
const [isOutputModalOpen, setIsOutputModalOpen] = useState(false);
useEffect(() => {
const isDevelopment = process.env.NODE_ENV === "development";
const script = document.createElement("script");
script.src = isDevelopment
? "/CPLmockData/SERVICE/de.js"
: "/CPL/SERVICE/de.js";
script.async = true;
script.onload = () => {
try {
if (
typeof win_de !== "undefined" &&
typeof win_counter !== "undefined" &&
typeof win_flutter !== "undefined"
) {
setMockData({
win_de,
win_counter,
win_flutter,
});
} else {
console.error("Mock-Daten konnten nicht geladen werden.");
}
} catch (error) {
console.error("Fehler beim Zugriff auf die globalen Daten:", error);
} finally {
setIsLoading(false);
}
};
script.onerror = () => {
console.error("Fehler beim Laden der Skript-Datei:", script.src);
setIsLoading(false);
};
document.body.appendChild(script);
return () => {
document.body.removeChild(script);
};
}, []);
const { mockData, isLoading } = useLoadScript();
const toggleSwitch = (id) => {
setDigitalOutputs((prevOutputs) =>