Mock Dateien für TDM erstellt:
Eine Liste mit den letzten 100 TDR Messungen des Slots
This commit is contained in:
41
redux/slices/tdmChartSlice.ts
Normal file
41
redux/slices/tdmChartSlice.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
||||
import { fetchAllTDMData } from "../thunks/fetchAllTDMThunk";
|
||||
import type { TDMEntry } from "../../types"; // optional, wenn ausgelagert
|
||||
|
||||
interface TDMChartState {
|
||||
data: TDMEntry[][]; // 32 Arrays (je Slot)
|
||||
loading: boolean;
|
||||
error: string | null;
|
||||
}
|
||||
|
||||
const initialState: TDMChartState = {
|
||||
data: [],
|
||||
loading: false,
|
||||
error: null,
|
||||
};
|
||||
|
||||
const tdmChartSlice = createSlice({
|
||||
name: "tdmChart",
|
||||
initialState,
|
||||
reducers: {},
|
||||
extraReducers: (builder) => {
|
||||
builder
|
||||
.addCase(fetchAllTDMData.pending, (state) => {
|
||||
state.loading = true;
|
||||
state.error = null;
|
||||
})
|
||||
.addCase(
|
||||
fetchAllTDMData.fulfilled,
|
||||
(state, action: PayloadAction<TDMEntry[][]>) => {
|
||||
state.loading = false;
|
||||
state.data = action.payload;
|
||||
}
|
||||
)
|
||||
.addCase(fetchAllTDMData.rejected, (state, action) => {
|
||||
state.loading = false;
|
||||
state.error = action.payload as string;
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
export default tdmChartSlice.reducer;
|
||||
@@ -16,6 +16,7 @@ import analogeEingaengeReducer from "./slices/analogeEingaengeSlice";
|
||||
import digitalInputsReducer from "./slices/digitalInputsSlice";
|
||||
import tdrReferenceChartReducer from "./slices/tdrReferenceChartSlice";
|
||||
import loopChartReducer from "./slices/loopChartSlice";
|
||||
import tdmChartReducer from "./slices/tdmChartSlice";
|
||||
|
||||
const store = configureStore({
|
||||
reducer: {
|
||||
@@ -34,6 +35,7 @@ const store = configureStore({
|
||||
tdrChart: tdrChartReducer,
|
||||
tdrReferenceChart: tdrReferenceChartReducer,
|
||||
loopChart: loopChartReducer,
|
||||
tdmChart: tdmChartReducer,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
23
redux/thunks/fetchAllTDMThunk.ts
Normal file
23
redux/thunks/fetchAllTDMThunk.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
// /redux/thunks/fetchAllTDMThunk.ts
|
||||
|
||||
import { createAsyncThunk } from "@reduxjs/toolkit";
|
||||
import { RootState } from "../store";
|
||||
import { fetchAllTDMDataFromServer } from "../../services/fetchAllTDMData";
|
||||
|
||||
export const fetchAllTDMData = createAsyncThunk(
|
||||
"tdmChart/fetchAllTDMData",
|
||||
async (_, { getState, rejectWithValue }) => {
|
||||
const currentData = (getState() as RootState).tdmChart.data;
|
||||
const newData = await fetchAllTDMDataFromServer();
|
||||
|
||||
if (newData.every((entry) => !entry)) {
|
||||
return rejectWithValue("Keine TDM-Daten empfangen.");
|
||||
}
|
||||
|
||||
if (JSON.stringify(currentData) !== JSON.stringify(newData)) {
|
||||
return newData;
|
||||
}
|
||||
|
||||
return rejectWithValue("Keine Änderungen in den TDM-Daten.");
|
||||
}
|
||||
);
|
||||
Reference in New Issue
Block a user