From 8e6b26dff964f5e0bd281053a49addda59dc1350 Mon Sep 17 00:00:00 2001 From: ISA Date: Tue, 25 Mar 2025 08:35:46 +0100 Subject: [PATCH] refactor: SystemSettings-Dispatch aus _app entfernt und in Seite 'Einstellungen' verlagert --- config/webVersion.ts | 2 +- pages/_app.tsx | 40 +-------------------------------- pages/analogeEingaenge.tsx | 16 +++++++++++++- pages/einausgaenge.tsx | 22 ++++++++++++++----- pages/einstellungen.tsx | 45 +++++++++++++++++++++++++++++++++++++- 5 files changed, 78 insertions(+), 47 deletions(-) diff --git a/config/webVersion.ts b/config/webVersion.ts index 0c7064d..ad7560d 100644 --- a/config/webVersion.ts +++ b/config/webVersion.ts @@ -6,5 +6,5 @@ 2: Patch oder Hotfix (Bugfixes oder kleine Änderungen). */ -const webVersion = "1.6.155"; +const webVersion = "1.6.156"; export default webVersion; diff --git a/pages/_app.tsx b/pages/_app.tsx index 31e2450..5d87edf 100644 --- a/pages/_app.tsx +++ b/pages/_app.tsx @@ -12,14 +12,11 @@ import WindowVariablesInitializer from "../components/WindowVariablesInitializer import "../styles/globals.css"; import { AppProps } from "next/app"; import { setVariables } from "../redux/slices/variablesSlice"; -import { setSystemSettings } from "../redux/slices/systemSettingsSlice"; import { setOpcUaZustand, setOpcUaActiveClientCount, setOpcUaNodesetName, } from "../redux/slices/opcuaSettingsSlice"; -import { fetchAnalogeEingaengeThunk } from "../redux/thunks/fetchAnalogeEingaengeThunk"; -import { fetchDigitaleEingaengeThunk } from "../redux/thunks/fetchDigitaleEingaengeThunk"; function MyApp({ Component, pageProps }: AppProps) { return ( @@ -60,22 +57,6 @@ function AppContent({ Component, pageProps }: AppProps) { ...restVariables } = variables; - dispatch( - setSystemSettings({ - deviceName, - mac1, - ip, - subnet, - gateway, - cplInternalTimestamp, - ntp1, - ntp2, - ntp3, - ntpTimezone, - ntpActive, - }) - ); - dispatch(setOpcUaZustand(opcUaZustand || "Offline")); dispatch(setOpcUaActiveClientCount(opcUaActiveClientCount || 0)); dispatch(setOpcUaNodesetName(opcUaNodesetName || "DefaultNodeset")); @@ -97,26 +78,7 @@ function AppContent({ Component, pageProps }: AppProps) { } }, []); //--------------------------------------------------------- - useEffect(() => { - if (typeof window !== "undefined") { - dispatch(fetchAnalogeEingaengeThunk()); - const interval = setInterval(() => { - dispatch(fetchAnalogeEingaengeThunk()); - }, 10000); - return () => clearInterval(interval); - } - }, [dispatch]); - //--------------------------------------------------------- - useEffect(() => { - if (typeof window !== "undefined") { - dispatch(fetchDigitaleEingaengeThunk()); - const interval = setInterval(() => { - dispatch(fetchDigitaleEingaengeThunk()); - }, 10000); - return () => clearInterval(interval); - } - }, [dispatch]); - //--------------------------------------------------------- + return (
diff --git a/pages/analogeEingaenge.tsx b/pages/analogeEingaenge.tsx index 371f142..405ea2a 100644 --- a/pages/analogeEingaenge.tsx +++ b/pages/analogeEingaenge.tsx @@ -1,10 +1,24 @@ "use client"; ///pages/analogeEingaenge.tsx -import React, { useState } from "react"; +import React, { useState, useEffect } from "react"; import AnalogeEingaengeTabelle from "../components/main/analogeEingaenge/AnalogeEingaengeTable"; import AnalogInputsChart from "../components/main/analogeEingaenge/AnalogInputsChart"; +import { fetchAnalogeEingaengeThunk } from "../redux/thunks/fetchAnalogeEingaengeThunk"; +import { useAppDispatch } from "../redux/store"; function AnalogeEingaenge() { const [activeConfig, setActiveConfig] = useState(null); + //--------------------------------------------------------- + const dispatch = useAppDispatch(); + useEffect(() => { + if (typeof window !== "undefined") { + dispatch(fetchAnalogeEingaengeThunk()); + const interval = setInterval(() => { + dispatch(fetchAnalogeEingaengeThunk()); + }, 10000); + return () => clearInterval(interval); + } + }, [dispatch]); + //--------------------------------------------------------- return (
diff --git a/pages/einausgaenge.tsx b/pages/einausgaenge.tsx index f5f5997..00a4b17 100644 --- a/pages/einausgaenge.tsx +++ b/pages/einausgaenge.tsx @@ -1,7 +1,7 @@ "use client"; // pages/einausgaenge.tsx "use client"; -import React, { useState } from "react"; +import React, { useState, useEffect } from "react"; import DigitalOutputs from "../components/main/einausgaenge/DigitalOutputs"; import DigitalInputs from "../components/main/einausgaenge/DigitalInputs"; import InputModal from "../components/main/einausgaenge/modals/InputModal"; @@ -9,10 +9,11 @@ import OutputModal from "../components/main/einausgaenge/modals/OutputModal"; import { useDigitalInputData } from "../hooks/einausgaenge/useDigitalInputsData"; import { useDigitalOutputs } from "../hooks/einausgaenge/useDigitalOutputsData"; import { useDispatch } from "react-redux"; +import { AppDispatch } from "../redux/store"; import { setDigitalOutputs } from "../redux/slices/digitalOutputsSlice"; - -function EinAusgaenge() { - const dispatch = useDispatch(); +import { fetchDigitaleEingaengeThunk } from "../redux/thunks/fetchDigitaleEingaengeThunk"; +const EinAusgaenge: React.FC = () => { + const dispatch = useDispatch(); const { digitalOutputs, isLoading: isLoadingOutputs } = useDigitalOutputs(); const { mockData, isLoading: isLoadingInputs } = useDigitalInputData(); @@ -63,6 +64,17 @@ function EinAusgaenge() { const inputsGroup1 = digitalInputs.slice(0, 16); const inputsGroup2 = digitalInputs.slice(16); + //--------------------------------------------------------- + useEffect(() => { + if (typeof window !== "undefined") { + dispatch(fetchDigitaleEingaengeThunk()); + const interval = setInterval(() => { + dispatch(fetchDigitaleEingaengeThunk()); + }, 10000); + return () => clearInterval(interval); + } + }, [dispatch]); + //--------------------------------------------------------- return (
@@ -103,6 +115,6 @@ function EinAusgaenge() { )}
); -} +}; export default EinAusgaenge; diff --git a/pages/einstellungen.tsx b/pages/einstellungen.tsx index 4b456a4..1860b39 100644 --- a/pages/einstellungen.tsx +++ b/pages/einstellungen.tsx @@ -1,9 +1,52 @@ -import React, { useState } from "react"; +import React, { useState, useEffect } from "react"; +import { useAppDispatch } from "../redux/store"; +import { setSystemSettings } from "../redux/slices/systemSettingsSlice"; +import { loadWindowVariables } from "../utils/loadWindowVariables"; import GeneralSettings from "../components/main/settingsPageComponents/GeneralSettings"; import OPCUAInterfaceSettings from "../components/main/settingsPageComponents/OPCUAInterfaceSettings"; export default function Settings() { const [activeTab, setActiveTab] = useState("tab1"); + const dispatch = useAppDispatch(); + + useEffect(() => { + const loadSettings = async () => { + const vars = await loadWindowVariables(); + if (!vars) return; + + const { + deviceName, + mac1, + ip, + subnet, + gateway, + cplInternalTimestamp, + ntp1, + ntp2, + ntp3, + ntpTimezone, + ntpActive, + } = vars; + + dispatch( + setSystemSettings({ + deviceName, + mac1, + ip, + subnet, + gateway, + cplInternalTimestamp, + ntp1, + ntp2, + ntp3, + ntpTimezone, + ntpActive, + }) + ); + }; + + loadSettings(); + }, [dispatch]); return (