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:
@@ -2,6 +2,7 @@
|
|||||||
import React, { useEffect } from "react";
|
import React, { useEffect } from "react";
|
||||||
import { useSelector, useDispatch } from "react-redux";
|
import { useSelector, useDispatch } from "react-redux";
|
||||||
import { RootState, AppDispatch } from "../../../redux/store";
|
import { RootState, AppDispatch } from "../../../redux/store";
|
||||||
|
import { fetchSystemSettingsThunk } from "../../../redux/thunks/fetchSystemSettingsThunk";
|
||||||
import { fetchOpcUaSettingsThunk } from "../../../redux/thunks/fetchOpcUaSettingsThunk";
|
import { fetchOpcUaSettingsThunk } from "../../../redux/thunks/fetchOpcUaSettingsThunk";
|
||||||
|
|
||||||
const NetworkInfo: React.FC = () => {
|
const NetworkInfo: React.FC = () => {
|
||||||
@@ -9,6 +10,7 @@ const NetworkInfo: React.FC = () => {
|
|||||||
|
|
||||||
// ✅ OPC UA Daten laden, wenn Komponente angezeigt wird
|
// ✅ OPC UA Daten laden, wenn Komponente angezeigt wird
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
dispatch(fetchSystemSettingsThunk());
|
||||||
dispatch(fetchOpcUaSettingsThunk());
|
dispatch(fetchOpcUaSettingsThunk());
|
||||||
}, [dispatch]);
|
}, [dispatch]);
|
||||||
// Werte direkt aus Redux holen
|
// Werte direkt aus Redux holen
|
||||||
|
|||||||
@@ -6,5 +6,5 @@
|
|||||||
2: Patch oder Hotfix (Bugfixes oder kleine Änderungen).
|
2: Patch oder Hotfix (Bugfixes oder kleine Änderungen).
|
||||||
|
|
||||||
*/
|
*/
|
||||||
const webVersion = "1.6.165";
|
const webVersion = "1.6.166";
|
||||||
export default webVersion;
|
export default webVersion;
|
||||||
|
|||||||
@@ -4,14 +4,12 @@
|
|||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { Provider } from "react-redux";
|
import { Provider } from "react-redux";
|
||||||
import store, { useAppDispatch } from "../redux/store";
|
import store, { useAppDispatch } from "../redux/store";
|
||||||
import { loadWindowVariables } from "../utils/loadWindowVariables";
|
|
||||||
import Header from "../components/header/Header";
|
import Header from "../components/header/Header";
|
||||||
import Navigation from "../components/navigation/Navigation";
|
import Navigation from "../components/navigation/Navigation";
|
||||||
import Footer from "../components/footer/Footer";
|
import Footer from "../components/footer/Footer";
|
||||||
import WindowVariablesInitializer from "../components/WindowVariablesInitializer";
|
import WindowVariablesInitializer from "../components/WindowVariablesInitializer";
|
||||||
import "../styles/globals.css";
|
import "../styles/globals.css";
|
||||||
import { AppProps } from "next/app";
|
import { AppProps } from "next/app";
|
||||||
import { setVariables } from "../redux/slices/variablesSlice";
|
|
||||||
|
|
||||||
function MyApp({ Component, pageProps }: AppProps) {
|
function MyApp({ Component, pageProps }: AppProps) {
|
||||||
return (
|
return (
|
||||||
@@ -28,28 +26,6 @@ function AppContent({ Component, pageProps }: AppProps) {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const loadAndStoreVariables = async () => {
|
const loadAndStoreVariables = async () => {
|
||||||
try {
|
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);
|
setSessionExpired(false);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("❌ Fehler beim Laden der Sitzung:", error);
|
console.error("❌ Fehler beim Laden der Sitzung:", error);
|
||||||
|
|||||||
12
redux/thunks/fetchSystemSettingsThunk.ts
Normal file
12
redux/thunks/fetchSystemSettingsThunk.ts
Normal 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));
|
||||||
|
}
|
||||||
|
);
|
||||||
17
services/fetchSystemSettings.ts
Normal file
17
services/fetchSystemSettings.ts
Normal 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,
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -46,18 +46,6 @@ interface OpcUaSettings {
|
|||||||
export async function loadWindowVariables(): Promise<Record<string, any>> {
|
export async function loadWindowVariables(): Promise<Record<string, any>> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const requiredVars: string[] = [
|
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_de_state",
|
||||||
"win_counter",
|
"win_counter",
|
||||||
"win_flutter",
|
"win_flutter",
|
||||||
@@ -135,7 +123,6 @@ export async function loadWindowVariables(): Promise<Record<string, any>> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// ✅ Redux mit Systemvariablen aktualisieren
|
// ✅ Redux mit Systemvariablen aktualisieren
|
||||||
loadAndStoreSystemSettings(win);
|
|
||||||
|
|
||||||
resolve(variablesObj);
|
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
|
// ✅ Funktion zum Speichern der digitalen Ausgänge in Redux
|
||||||
const loadAndStoreDigitalOutputs = (win: CustomWindow) => {
|
const loadAndStoreDigitalOutputs = (win: CustomWindow) => {
|
||||||
console.log("Prüfe digitale Ausgänge in window:");
|
console.log("Prüfe digitale Ausgänge in window:");
|
||||||
|
|||||||
Reference in New Issue
Block a user