refactor: SystemSettings-Dispatch aus _app entfernt und in Seite 'Einstellungen' verlagert

This commit is contained in:
ISA
2025-03-25 08:35:46 +01:00
parent 6730ba92be
commit 8e6b26dff9
5 changed files with 78 additions and 47 deletions

View File

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

View File

@@ -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 (
<div className="flex flex-col h-screen overflow-hidden">
<WindowVariablesInitializer />

View File

@@ -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<number | null>(null);
//---------------------------------------------------------
const dispatch = useAppDispatch();
useEffect(() => {
if (typeof window !== "undefined") {
dispatch(fetchAnalogeEingaengeThunk());
const interval = setInterval(() => {
dispatch(fetchAnalogeEingaengeThunk());
}, 10000);
return () => clearInterval(interval);
}
}, [dispatch]);
//---------------------------------------------------------
return (
<div className="flex flex-col gap-3 p-4 h-[calc(100vh-13vh-8vh)] laptop:h-[calc(100vh-10vh-5vh)] xl:h-[calc(100vh-10vh-6vh)] laptop:gap-0">

View File

@@ -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<AppDispatch>();
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 (
<div className="p-4">
@@ -103,6 +115,6 @@ function EinAusgaenge() {
)}
</div>
);
}
};
export default EinAusgaenge;

View File

@@ -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 (
<div className="p-4">