diff --git a/components/main/uebersicht/NetworkInfo.tsx b/components/main/uebersicht/NetworkInfo.tsx index b51f4dd..2da4d37 100644 --- a/components/main/uebersicht/NetworkInfo.tsx +++ b/components/main/uebersicht/NetworkInfo.tsx @@ -2,6 +2,7 @@ import React, { useEffect } from "react"; import { useSelector, useDispatch } from "react-redux"; import { RootState, AppDispatch } from "../../../redux/store"; +import { fetchSystemSettingsThunk } from "../../../redux/thunks/fetchSystemSettingsThunk"; import { fetchOpcUaSettingsThunk } from "../../../redux/thunks/fetchOpcUaSettingsThunk"; const NetworkInfo: React.FC = () => { @@ -9,6 +10,7 @@ const NetworkInfo: React.FC = () => { // ✅ OPC UA Daten laden, wenn Komponente angezeigt wird useEffect(() => { + dispatch(fetchSystemSettingsThunk()); dispatch(fetchOpcUaSettingsThunk()); }, [dispatch]); // Werte direkt aus Redux holen diff --git a/config/webVersion.ts b/config/webVersion.ts index 13441be..7eba3b5 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.165"; +const webVersion = "1.6.166"; export default webVersion; diff --git a/pages/_app.tsx b/pages/_app.tsx index 92a5915..eee2908 100644 --- a/pages/_app.tsx +++ b/pages/_app.tsx @@ -4,14 +4,12 @@ import { useEffect, useState } from "react"; import { Provider } from "react-redux"; import store, { useAppDispatch } from "../redux/store"; -import { loadWindowVariables } from "../utils/loadWindowVariables"; import Header from "../components/header/Header"; import Navigation from "../components/navigation/Navigation"; import Footer from "../components/footer/Footer"; import WindowVariablesInitializer from "../components/WindowVariablesInitializer"; import "../styles/globals.css"; import { AppProps } from "next/app"; -import { setVariables } from "../redux/slices/variablesSlice"; function MyApp({ Component, pageProps }: AppProps) { return ( @@ -28,28 +26,6 @@ function AppContent({ Component, pageProps }: AppProps) { useEffect(() => { const loadAndStoreVariables = async () => { try { - const variables = await loadWindowVariables(); - if (!variables) throw new Error("Sitzungsfehler"); - - //console.log("✅ Window-Variablen geladen:", variables); - - const { - deviceName, - mac1, - ip, - subnet, - gateway, - cplInternalTimestamp, - ntp1, - ntp2, - ntp3, - ntpTimezone, - ntpActive, - ...restVariables - } = variables; - - dispatch(setVariables(restVariables)); - setSessionExpired(false); } catch (error) { console.error("❌ Fehler beim Laden der Sitzung:", error); diff --git a/redux/thunks/fetchSystemSettingsThunk.ts b/redux/thunks/fetchSystemSettingsThunk.ts new file mode 100644 index 0000000..0a78266 --- /dev/null +++ b/redux/thunks/fetchSystemSettingsThunk.ts @@ -0,0 +1,12 @@ +// /redux/thunks/fetchSystemSettingsThunk.ts +import { createAsyncThunk } from "@reduxjs/toolkit"; +import { fetchSystemSettings } from "../../services/fetchSystemSettings"; +import { setSystemSettings } from "../slices/systemSettingsSlice"; + +export const fetchSystemSettingsThunk = createAsyncThunk( + "systemSettings/fetch", + async (_, { dispatch }) => { + const data = await fetchSystemSettings(); + if (data) dispatch(setSystemSettings(data)); + } +); diff --git a/services/fetchSystemSettings.ts b/services/fetchSystemSettings.ts new file mode 100644 index 0000000..2f9d4ea --- /dev/null +++ b/services/fetchSystemSettings.ts @@ -0,0 +1,17 @@ +// /services/fetchSystemSettings.ts +export const fetchSystemSettings = async () => { + const win = window as any; + return { + deviceName: win.win_deviceName || "", + mac1: win.win_mac1 || "", + ip: win.win_ip || "", + subnet: win.win_subnet || "", + gateway: win.win_gateway || "", + cplInternalTimestamp: win.win_cplInternalTimestamp || "", + ntp1: win.win_ntp1 || "", + ntp2: win.win_ntp2 || "", + ntp3: win.win_ntp3 || "", + ntpTimezone: win.win_ntpTimezone || "", + ntpActive: win.win_ntpActive || false, + }; +}; diff --git a/utils/loadWindowVariables.ts b/utils/loadWindowVariables.ts index 42b4c5d..5c1333e 100644 --- a/utils/loadWindowVariables.ts +++ b/utils/loadWindowVariables.ts @@ -46,18 +46,6 @@ interface OpcUaSettings { export async function loadWindowVariables(): Promise> { return new Promise((resolve, reject) => { const requiredVars: string[] = [ - "win_deviceName", - "win_mac1", - "win_ip", - "win_subnet", - "win_gateway", - "win_cplInternalTimestamp", - "win_ntp1", - "win_ntp2", - "win_ntp3", - "win_systemZeit", - "win_ntpTimezone", - "win_ntpActive", "win_de_state", "win_counter", "win_flutter", @@ -135,7 +123,6 @@ export async function loadWindowVariables(): Promise> { ); // ✅ Redux mit Systemvariablen aktualisieren - loadAndStoreSystemSettings(win); resolve(variablesObj); }) @@ -146,25 +133,6 @@ export async function loadWindowVariables(): Promise> { }); } -// ✅ Funktion zum Speichern von System-Variablen in Redux -const loadAndStoreSystemSettings = (win: CustomWindow) => { - const settings: SystemSettings = { - deviceName: win.win_deviceName || "", - mac1: win.win_mac1 || "", - ip: win.win_ip || "", - subnet: win.win_subnet || "", - gateway: win.win_gateway || "", - cplInternalTimestamp: win.win_cplInternalTimestamp || "", - ntp1: win.win_ntp1 || "", - ntp2: win.win_ntp2 || "", - ntp3: win.win_ntp3 || "", - ntpTimezone: win.win_ntpTimezone || "", - ntpActive: win.win_ntpActive || false, - }; - - store.dispatch(setSystemSettings(settings)); -}; - // ✅ Funktion zum Speichern der digitalen Ausgänge in Redux const loadAndStoreDigitalOutputs = (win: CustomWindow) => { console.log("Prüfe digitale Ausgänge in window:");