git commit -m "refactor: last20Messages aus _app.tsx entfernt und über Thunk in dashboard.tsx geladen"
This commit is contained in:
@@ -6,5 +6,5 @@
|
||||
2: Patch oder Hotfix (Bugfixes oder kleine Änderungen).
|
||||
|
||||
*/
|
||||
const webVersion = "1.6.156";
|
||||
const webVersion = "1.6.157";
|
||||
export default webVersion;
|
||||
|
||||
@@ -12,11 +12,6 @@ import WindowVariablesInitializer from "../components/WindowVariablesInitializer
|
||||
import "../styles/globals.css";
|
||||
import { AppProps } from "next/app";
|
||||
import { setVariables } from "../redux/slices/variablesSlice";
|
||||
import {
|
||||
setOpcUaZustand,
|
||||
setOpcUaActiveClientCount,
|
||||
setOpcUaNodesetName,
|
||||
} from "../redux/slices/opcuaSettingsSlice";
|
||||
|
||||
function MyApp({ Component, pageProps }: AppProps) {
|
||||
return (
|
||||
@@ -39,7 +34,6 @@ function AppContent({ Component, pageProps }: AppProps) {
|
||||
//console.log("✅ Window-Variablen geladen:", variables);
|
||||
|
||||
const {
|
||||
last20Messages,
|
||||
opcUaZustand,
|
||||
opcUaActiveClientCount,
|
||||
opcUaNodesetName,
|
||||
@@ -57,10 +51,6 @@ function AppContent({ Component, pageProps }: AppProps) {
|
||||
...restVariables
|
||||
} = variables;
|
||||
|
||||
dispatch(setOpcUaZustand(opcUaZustand || "Offline"));
|
||||
dispatch(setOpcUaActiveClientCount(opcUaActiveClientCount || 0));
|
||||
dispatch(setOpcUaNodesetName(opcUaNodesetName || "DefaultNodeset"));
|
||||
|
||||
dispatch(setVariables(restVariables));
|
||||
|
||||
setSessionExpired(false);
|
||||
|
||||
@@ -9,8 +9,21 @@ import Last20MessagesTable from "../components/main/uebersicht/Last20MessagesTab
|
||||
import NetworkInfo from "../components/main/uebersicht/NetworkInfo";
|
||||
import VersionInfo from "../components/main/uebersicht/VersionInfo";
|
||||
import Baugruppentraeger from "../components/main/uebersicht/Baugruppentraeger";
|
||||
import { fetchLast20MessagesThunk } from "../redux/thunks/fetchLast20MessagesThunk";
|
||||
import { useAppDispatch } from "../redux/store";
|
||||
|
||||
const Dashboard: React.FC = () => {
|
||||
//-------------------------------------
|
||||
const dispatch = useAppDispatch();
|
||||
useEffect(() => {
|
||||
dispatch(fetchLast20MessagesThunk());
|
||||
const interval = setInterval(() => {
|
||||
dispatch(fetchLast20MessagesThunk());
|
||||
}, 10000); // oder 5000
|
||||
|
||||
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">
|
||||
{/* Header */}
|
||||
|
||||
12
redux/thunks/fetchLast20MessagesThunk.ts
Normal file
12
redux/thunks/fetchLast20MessagesThunk.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { createAsyncThunk } from "@reduxjs/toolkit";
|
||||
import { fetchLast20MessagesFromWindow } from "../../services/fetchLast20Messages";
|
||||
import { setLast20Messages } from "../slices/dashboardSlice";
|
||||
|
||||
export const fetchLast20MessagesThunk = createAsyncThunk(
|
||||
"dashboard/fetchLast20Messages",
|
||||
async (_, { dispatch }) => {
|
||||
const messages = await fetchLast20MessagesFromWindow();
|
||||
dispatch(setLast20Messages(messages));
|
||||
return messages;
|
||||
}
|
||||
);
|
||||
9
services/fetchLast20Messages.ts
Normal file
9
services/fetchLast20Messages.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
export async function fetchLast20MessagesFromWindow(): Promise<string | null> {
|
||||
return new Promise((resolve) => {
|
||||
if (typeof window !== "undefined" && (window as any).win_last20Messages) {
|
||||
resolve((window as any).win_last20Messages);
|
||||
} else {
|
||||
resolve(null);
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user