refactor: Systemdaten über eigenen Redux Thunk und Service laden

- Systeminformationen (IP, Subnetz, Gateway, NTP, etc.) werden nun über fetchSystemSettingsThunk geladen
- loadWindowVariables.ts von systemSettings-Logik bereinigt
- Aufruf erfolgt lokal in NetworkInfo.tsx statt global in _app.tsx
- Verbesserte Struktur, reduzierte Netzwerklast, klarere Trennung der Zuständigkeiten
This commit is contained in:
ISA
2025-03-26 11:28:13 +01:00
parent 7b85ebc730
commit fa94d2c2f7
6 changed files with 32 additions and 57 deletions

View File

@@ -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

View File

@@ -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;

View File

@@ -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);

View File

@@ -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));
}
);

View File

@@ -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,
};
};

View File

@@ -46,18 +46,6 @@ interface OpcUaSettings {
export async function loadWindowVariables(): Promise<Record<string, any>> {
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<Record<string, any>> {
);
// ✅ Redux mit Systemvariablen aktualisieren
loadAndStoreSystemSettings(win);
resolve(variablesObj);
})
@@ -146,25 +133,6 @@ export async function loadWindowVariables(): Promise<Record<string, any>> {
});
}
// ✅ 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:");