feat: automatische Redux-Initialisierung in _app.tsx basierend auf Seite
- zentrale Datenaktualisierung per Thunk alle 10 Sekunden - alle Seiten wie dashboard, kabelueberwachung, digitale/analoge Ein-/Ausgänge etc. werden erkannt - automatische Zuordnung der richtigen Redux-Thunks - README.md und CHANGELOG.md aktualisiert - Version auf 1.6.400 erhöht
This commit is contained in:
14
CHANGELOG.md
14
CHANGELOG.md
@@ -4,6 +4,20 @@ Alle Änderungen und Versionen des CPLv4.0 Frontends chronologisch dokumentiert.
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## [1.6.400] – 2025-05-13
|
||||||
|
|
||||||
|
### Feature
|
||||||
|
|
||||||
|
- In `_app.tsx` wurde ein zentrales Redux-Update-System implementiert:
|
||||||
|
- Die aktuelle Seite wird automatisch erkannt (`window.location.pathname`)
|
||||||
|
- Abhängig von der Seite werden die passenden Thunks geladen (z. B. `fetchKueDataThunk`, `fetchDigitalOutputsThunk` usw.)
|
||||||
|
- Die Daten werden alle 10 Sekunden erneut geladen
|
||||||
|
- Dadurch muss auf den Unterseiten kein separater Redux-Aufruf mehr erfolgen
|
||||||
|
- Unterstützt alle Slices: digitale/analoge Ein- und Ausgänge, Meldungen, Systemstatus, Einstellungen, TDR/Loop-Daten
|
||||||
|
- Reduziert Hardwarelast durch seitenbezogene API-Calls
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## [1.6.399] – 2025-05-12
|
## [1.6.399] – 2025-05-12
|
||||||
|
|
||||||
### fix
|
### fix
|
||||||
|
|||||||
@@ -6,5 +6,5 @@
|
|||||||
2: Patch oder Hotfix (Bugfixes oder kleine Änderungen).
|
2: Patch oder Hotfix (Bugfixes oder kleine Änderungen).
|
||||||
|
|
||||||
*/
|
*/
|
||||||
const webVersion = "1.6.399";
|
const webVersion = "1.6.400";
|
||||||
export default webVersion;
|
export default webVersion;
|
||||||
|
|||||||
@@ -4,14 +4,28 @@
|
|||||||
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 { AppProps } from "next/app";
|
||||||
import { loadWindowVariables } from "../utils/loadWindowVariables";
|
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 { setKueData } from "../redux/slices/kueDataSlice";
|
|
||||||
|
// Thunks importieren
|
||||||
|
import { fetchKueDataThunk } from "../redux/thunks/fetchKueDataThunk";
|
||||||
|
import { fetchDigitalOutputsThunk } from "../redux/thunks/fetchDigitalOutputsThunk";
|
||||||
|
import { fetchAnalogeEingaengeThunk } from "../redux/thunks/fetchAnalogeEingaengeThunk";
|
||||||
|
import { fetchAnalogInputsHistoryThunk } from "../redux/thunks/fetchAnalogInputsHistoryThunk";
|
||||||
|
import { fetchLast20MessagesThunk } from "../redux/thunks/fetchLast20MessagesThunk";
|
||||||
|
import { fetchOpcUaSettingsThunk } from "../redux/thunks/fetchOpcUaSettingsThunk";
|
||||||
|
import { fetchSystemSettingsThunk } from "../redux/thunks/fetchSystemSettingsThunk";
|
||||||
|
import { fetchSystemVoltTempThunk } from "../redux/thunks/fetchSystemVoltTempThunk";
|
||||||
|
import { fetchReferenceCurveBySlotThunk } from "../redux/thunks/fetchReferenceCurveBySlotThunk";
|
||||||
|
import { fetchAllTDRReferenceChartThunk } from "../redux/thunks/fetchAllTDRReferenceChartThunk";
|
||||||
|
import { fetchTDRChartDataByIdThunk } from "../redux/thunks/fetchTDRChartDataByIdThunk";
|
||||||
|
import { fetchLoopChartDataThunk } from "../redux/thunks/fetchLoopChartDataThunk";
|
||||||
|
|
||||||
import "../styles/globals.css";
|
import "../styles/globals.css";
|
||||||
import { AppProps } from "next/app";
|
|
||||||
|
|
||||||
function MyApp({ Component, pageProps }: AppProps) {
|
function MyApp({ Component, pageProps }: AppProps) {
|
||||||
return (
|
return (
|
||||||
@@ -27,32 +41,41 @@ function AppContent({ Component, pageProps }: AppProps) {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let intervalId: NodeJS.Timeout;
|
let intervalId: NodeJS.Timeout;
|
||||||
|
const pathname = window.location.pathname;
|
||||||
|
|
||||||
const loadAndStoreVariables = async () => {
|
const loadAndDispatch = () => {
|
||||||
try {
|
if (pathname.includes("kabelueberwachung")) {
|
||||||
const { variables, kueData } = await loadWindowVariables();
|
dispatch(fetchKueDataThunk());
|
||||||
if (!variables) throw new Error("Sitzungsfehler");
|
} else if (pathname.includes("digitalOutputs")) {
|
||||||
|
dispatch(fetchDigitalOutputsThunk());
|
||||||
// Nur auf kabelueberwachung.html Redux aktualisieren
|
} else if (pathname.includes("digitalInputs")) {
|
||||||
if (window.location.pathname.includes("kabelueberwachung")) {
|
dispatch(fetchDigitalOutputsThunk()); // 🟠 evtl. anpassen
|
||||||
dispatch(setKueData(kueData));
|
} else if (pathname.includes("analogeEingaenge")) {
|
||||||
}
|
dispatch(fetchAnalogeEingaengeThunk());
|
||||||
|
} else if (pathname.includes("analogHistory")) {
|
||||||
setSessionExpired(false);
|
dispatch(fetchAnalogInputsHistoryThunk());
|
||||||
} catch (error) {
|
} else if (pathname.includes("dashboard")) {
|
||||||
console.error("❌ Fehler beim Laden der Sitzung:", error);
|
dispatch(fetchLast20MessagesThunk());
|
||||||
setSessionExpired(true);
|
} else if (pathname.includes("einstellungen")) {
|
||||||
|
dispatch(fetchOpcUaSettingsThunk());
|
||||||
|
} else if (pathname.includes("systemvolt")) {
|
||||||
|
dispatch(fetchSystemVoltTempThunk());
|
||||||
|
} else if (pathname.includes("system")) {
|
||||||
|
dispatch(fetchSystemSettingsThunk());
|
||||||
|
} else if (pathname.includes("tdrRef")) {
|
||||||
|
dispatch(fetchAllTDRReferenceChartThunk());
|
||||||
|
} else if (pathname.includes("tdrSlot")) {
|
||||||
|
dispatch(fetchReferenceCurveBySlotThunk());
|
||||||
|
} else if (pathname.includes("tdrId")) {
|
||||||
|
dispatch(fetchTDRChartDataByIdThunk());
|
||||||
|
} else if (pathname.includes("loopChart")) {
|
||||||
|
dispatch(fetchLoopChartDataThunk());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (typeof window !== "undefined") {
|
if (typeof window !== "undefined") {
|
||||||
loadAndStoreVariables();
|
loadAndDispatch();
|
||||||
|
intervalId = setInterval(loadAndDispatch, 10000);
|
||||||
// Nur auf kabelueberwachung.html regelmäßig aktualisieren
|
|
||||||
if (window.location.pathname.includes("kabelueberwachung")) {
|
|
||||||
intervalId = setInterval(loadAndStoreVariables, 10000);
|
|
||||||
}
|
|
||||||
|
|
||||||
return () => clearInterval(intervalId);
|
return () => clearInterval(intervalId);
|
||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|||||||
BIN
redux/slices/slices.zip
Normal file
BIN
redux/slices/slices.zip
Normal file
Binary file not shown.
BIN
redux/thunks/thunks.zip
Normal file
BIN
redux/thunks/thunks.zip
Normal file
Binary file not shown.
Reference in New Issue
Block a user