refactor: lade TDM-Liste nur im TDR-Modus über TDRChartActionBar
- fetchTDMDataBySlotThunk aus ChartSwitcher entfernt - TDM-Daten werden jetzt gezielt im TDR-Kontext geladen - Vermeidet Konflikte mit Schleifenmodus und spart Ressourcen
This commit is contained in:
52
redux/slices/tdmSingleChartSlice.ts
Normal file
52
redux/slices/tdmSingleChartSlice.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
// /redux/slices/tdmSingleChartSlice.ts
|
||||
|
||||
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
||||
import { fetchTDMDataBySlotThunk } from "../thunks/fetchTDMDataBySlotThunk";
|
||||
|
||||
interface TDMChartEntry {
|
||||
id: number;
|
||||
t: string;
|
||||
}
|
||||
|
||||
interface TDMChartState {
|
||||
data: {
|
||||
[slot: number]: TDMChartEntry[];
|
||||
};
|
||||
loading: boolean;
|
||||
error: string | null;
|
||||
}
|
||||
|
||||
const initialState: TDMChartState = {
|
||||
data: {},
|
||||
loading: false,
|
||||
error: null,
|
||||
};
|
||||
|
||||
const tdmSingleChartSlice = createSlice({
|
||||
name: "tdmSingleChart",
|
||||
initialState,
|
||||
reducers: {},
|
||||
extraReducers: (builder) => {
|
||||
builder
|
||||
.addCase(fetchTDMDataBySlotThunk.pending, (state) => {
|
||||
state.loading = true;
|
||||
state.error = null;
|
||||
})
|
||||
.addCase(
|
||||
fetchTDMDataBySlotThunk.fulfilled,
|
||||
(
|
||||
state,
|
||||
action: PayloadAction<{ slot: number; data: TDMChartEntry[] }>
|
||||
) => {
|
||||
state.loading = false;
|
||||
state.data[action.payload.slot] = action.payload.data;
|
||||
}
|
||||
)
|
||||
.addCase(fetchTDMDataBySlotThunk.rejected, (state, action) => {
|
||||
state.loading = false;
|
||||
state.error = action.error.message ?? "Unbekannter Fehler";
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
export default tdmSingleChartSlice.reducer;
|
||||
@@ -20,6 +20,7 @@ import tdrDataByIdReducer from "./slices/tdrDataByIdSlice";
|
||||
import kueDataReducer from "./slices/kueDataSlice";
|
||||
import selectedChartDataReducer from "./slices/selectedChartDataSlice";
|
||||
import tdrSingleChartReducer from "./slices/tdrSingleChartSlice";
|
||||
import tdmSingleChartReducer from "./slices/tdmSingleChartSlice";
|
||||
|
||||
const store = configureStore({
|
||||
reducer: {
|
||||
@@ -42,6 +43,7 @@ const store = configureStore({
|
||||
kueData: kueDataReducer,
|
||||
selectedChartData: selectedChartDataReducer,
|
||||
tdrSingleChart: tdrSingleChartReducer,
|
||||
tdmSingleChart: tdmSingleChartReducer,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user