From 4b7c87198b9962723752ac143643b3c7b414a5af Mon Sep 17 00:00:00 2001 From: ISA Date: Wed, 22 Jan 2025 15:26:02 +0100 Subject: [PATCH] =?UTF-8?q?Digitale=20Eing=C3=A4nge=20kommen=20von=20Mock?= =?UTF-8?q?=20oder=20echte=20Daten=20je=20nach=20dem=20Umgebung=20(Produkt?= =?UTF-8?q?ion/echte=20oder=20Entwicklung/Mock)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/einausgaenge.js | 161 ++++++++++++++++++++---------------------- 1 file changed, 77 insertions(+), 84 deletions(-) diff --git a/pages/einausgaenge.js b/pages/einausgaenge.js index fd657be..b0003c7 100644 --- a/pages/einausgaenge.js +++ b/pages/einausgaenge.js @@ -1,15 +1,29 @@ -"use client"; // pages/einausgaenge.js +"use client"; // Falls notwendig import React, { useState, useEffect } from "react"; import { Icon } from "@iconify/react"; function EinAusgaenge() { const [mockData, setMockData] = useState({ - win_de: Array(32).fill(0), // Fallback-Daten für die Initialisierung + 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 }, + { id: 2, description: "Ausgang2", toggle: false }, + { id: 3, description: "Ausgang3", toggle: true }, + { id: 4, description: "Ausgang4", toggle: false }, + ]); + + // Modal-Zustände + const [selectedInput, setSelectedInput] = useState(null); + const [selectedOutput, setSelectedOutput] = useState(null); + const [isInputModalOpen, setIsInputModalOpen] = useState(false); + const [isOutputModalOpen, setIsOutputModalOpen] = useState(false); + useEffect(() => { const isDevelopment = process.env.NODE_ENV === "development"; const script = document.createElement("script"); @@ -21,7 +35,6 @@ function EinAusgaenge() { script.onload = () => { try { - // Sicherstellen, dass die globalen Variablen verfügbar sind if ( typeof win_de !== "undefined" && typeof win_counter !== "undefined" && @@ -54,24 +67,6 @@ function EinAusgaenge() { }; }, []); - // Hook-Anzahl konstant halten - const digitalInputs = mockData.win_de.map((status, index) => ({ - id: index + 1, - status: status === 1 ? "active" : "inactive", - description: `DE${index + 1}`, - isInverted: false, - })); - - const inputsGroup1 = digitalInputs.slice(0, 16); - const inputsGroup2 = digitalInputs.slice(16); - - const [digitalOutputs, setDigitalOutputs] = useState([ - { id: 1, description: "Ausgang1", toggle: true }, - { id: 2, description: "Ausgang2", toggle: false }, - { id: 3, description: "Ausgang3", toggle: true }, - { id: 4, description: "Ausgang4", toggle: false }, - ]); - const toggleSwitch = (id) => { setDigitalOutputs((prevOutputs) => prevOutputs.map((output) => @@ -80,11 +75,6 @@ function EinAusgaenge() { ); }; - const [selectedInput, setSelectedInput] = useState(null); - const [selectedOutput, setSelectedOutput] = useState(null); - const [isInputModalOpen, setIsInputModalOpen] = useState(false); - const [isOutputModalOpen, setIsOutputModalOpen] = useState(false); - const openInputModal = (input) => { setSelectedInput(input); setIsInputModalOpen(true); @@ -105,12 +95,16 @@ function EinAusgaenge() { setIsOutputModalOpen(false); }; - // Warten auf Daten - if (isLoading) { - return
Daten werden geladen...
; - } + const digitalInputs = mockData.win_de.map((status, index) => ({ + id: index + 1, + status: status === 1 ? "active" : "inactive", + description: `DE${index + 1}`, + isInverted: false, + })); + + const inputsGroup1 = digitalInputs.slice(0, 16); + const inputsGroup2 = digitalInputs.slice(16); - //-------------------------------------------- return (

Ein- und Ausgänge

@@ -170,57 +164,59 @@ function EinAusgaenge() { ))}
- - {/* Digitale Ausgänge */} -
-

- - Digitale Ausgänge -

- - - - - - - - - - - {digitalOutputs.map((output) => ( - - - - - + {/* Digitale Ausgänge */} +
+

+ + Digitale Ausgänge +

+
AusgangBezeichnungSchalterAktion
- - {output.id} - {output.description} - toggleSwitch(output.id)} - className={`cursor-pointer text-2xl transform ${ - output.toggle - ? "text-blue-500 scale-x-100" - : "text-gray-500 scale-x-[-1]" - }`} - title={`Schalter ${output.toggle ? "EIN" : "AUS"} schalten`} - /> - - openOutputModal(output)} - /> -
+ + + + + + - ))} - -
AusgangBezeichnungSchalterAktion
+ + + {digitalOutputs.map((output) => ( + + + + {output.id} + + {output.description} + + toggleSwitch(output.id)} + className={`cursor-pointer text-2xl transform ${ + output.toggle + ? "text-blue-500 scale-x-100" + : "text-gray-500 scale-x-[-1]" + }`} + title={`Schalter ${ + output.toggle ? "EIN" : "AUS" + } schalten`} + /> + + + openOutputModal(output)} + /> + + + ))} + + +
{/* Modal für Eingänge */} @@ -237,10 +233,6 @@ function EinAusgaenge() {

Beschreibung: {selectedInput.description}

-

- Invertiert:{" "} - {selectedInput.isInverted ? "Ja" : "Nein"} -