refactor: lade OPC UA Daten direkt in NetworkInfo-Komponente statt global in _app.tsx
- Thunk `fetchOpcUaSettingsThunk` wird jetzt nur bei Anzeige von NetworkInfo ausgeführt - Reduzierte Netzwerklast und bessere Trennung von Zuständigkeiten - Entfernt globalen OPC UA-Aufruf aus _app.tsx
This commit is contained in:
@@ -1,22 +0,0 @@
|
||||
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
||||
|
||||
interface TestState {
|
||||
testData: any[];
|
||||
}
|
||||
|
||||
const initialState: TestState = {
|
||||
testData: [],
|
||||
};
|
||||
|
||||
const testSlice = createSlice({
|
||||
name: "test",
|
||||
initialState,
|
||||
reducers: {
|
||||
setTestData: (state, action: PayloadAction<any[]>) => {
|
||||
state.testData = action.payload;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const { setTestData } = testSlice.actions;
|
||||
export default testSlice.reducer;
|
||||
@@ -1,3 +1,4 @@
|
||||
// /redux/thunks/fetchLast20MessagesThunk.ts
|
||||
import { createAsyncThunk } from "@reduxjs/toolkit";
|
||||
import { fetchLast20MessagesFromWindow } from "../../services/fetchLast20Messages";
|
||||
import { setLast20Messages } from "../slices/last20MessagesSlice";
|
||||
|
||||
24
redux/thunks/fetchOpcUaSettingsThunk.ts
Normal file
24
redux/thunks/fetchOpcUaSettingsThunk.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
// ✅ 2. Thunk: /redux/thunks/fetchOpcUaSettingsThunk.ts
|
||||
import { createAsyncThunk } from "@reduxjs/toolkit";
|
||||
import { fetchOpcUaSettings } from "../../services/fetchOpcUaSettings";
|
||||
import {
|
||||
setOpcUaZustand,
|
||||
setOpcUaEncryption,
|
||||
setOpcUaActiveClientCount,
|
||||
setOpcUaNodesetName,
|
||||
setOpcUaUsers,
|
||||
} from "../slices/opcuaSettingsSlice";
|
||||
|
||||
export const fetchOpcUaSettingsThunk = createAsyncThunk(
|
||||
"opcuaSettings/fetch",
|
||||
async (_, { dispatch }) => {
|
||||
const data = await fetchOpcUaSettings();
|
||||
if (!data) return;
|
||||
|
||||
dispatch(setOpcUaZustand(data.zustand));
|
||||
dispatch(setOpcUaEncryption(data.encryption));
|
||||
dispatch(setOpcUaActiveClientCount(data.clientCount));
|
||||
dispatch(setOpcUaNodesetName(data.nodesetName));
|
||||
dispatch(setOpcUaUsers(data.users));
|
||||
}
|
||||
);
|
||||
Reference in New Issue
Block a user