feat: Redux-Struktur für LoopChart vereinheitlicht (DIA0–2 + Typ 3/4)

- Alle Schleifen- und Isolationswiderstandsdaten werden zentral in loopChart.data gespeichert
- Redux State unterstützt nun strukturierte Speicherung nach mode (DIA0–DIA2) und type (3/4)
- Bestehender Thunk fetchLoopChartDataThunk wurde angepasst zur Wiederverwendung
- Zugriff aus Komponente via loopData["DIAx"][type] möglich
This commit is contained in:
Ismail Ali
2025-03-23 18:07:00 +01:00
parent 39f3dbfb6c
commit 44db20a871
7 changed files with 122 additions and 5 deletions

View File

@@ -0,0 +1,48 @@
// /redux/slices/loopChartSlice.ts
import { createSlice } from "@reduxjs/toolkit";
import { fetchLoopChartDataThunk } from "../thunks/fetchLoopChartDataThunk";
interface ChartData {
[mode: string]: {
[type: number]: any;
};
}
interface LoopChartState {
data: ChartData;
loading: boolean;
error: string | null;
}
const initialState: LoopChartState = {
data: {},
loading: false,
error: null,
};
const loopChartSlice = createSlice({
name: "loopChart",
initialState,
reducers: {},
extraReducers: (builder) => {
builder
.addCase(fetchLoopChartDataThunk.pending, (state) => {
state.loading = true;
state.error = null;
})
.addCase(fetchLoopChartDataThunk.fulfilled, (state, action) => {
state.loading = false;
const { mode, type } = action.meta.arg;
if (!state.data[mode]) {
state.data[mode] = {};
}
state.data[mode][type] = action.payload;
})
.addCase(fetchLoopChartDataThunk.rejected, (state, action) => {
state.loading = false;
state.error = action.payload as string;
});
},
});
export default loopChartSlice.reducer;