refactor: TDR-Daten in neuen tdrSingleChartSlice ausgelagert und nur pro Slot geladen
- Globalen fetchAllTDRChartData entfernt - Neuen Slice und Thunk pro Slot erstellt - TDRChart liest initiale Daten aus neuem Slice
This commit is contained in:
53
redux/slices/tdrSingleChartSlice.ts
Normal file
53
redux/slices/tdrSingleChartSlice.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
// redux/slices/tdrSingleChartSlice.ts
|
||||
|
||||
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
||||
import { fetchTDRChartDataBySlotThunk } from "../thunks/fetchTDRChartDataBySlotThunk";
|
||||
|
||||
interface TDRSlotData {
|
||||
[slot: number]: { d: number; p: number }[];
|
||||
}
|
||||
|
||||
interface TdrSingleChartState {
|
||||
data: TDRSlotData;
|
||||
loading: boolean;
|
||||
error: string | null;
|
||||
}
|
||||
|
||||
const initialState: TdrSingleChartState = {
|
||||
data: {},
|
||||
loading: false,
|
||||
error: null,
|
||||
};
|
||||
|
||||
const tdrSingleChartSlice = createSlice({
|
||||
name: "tdrSingleChart",
|
||||
initialState,
|
||||
reducers: {},
|
||||
extraReducers: (builder) => {
|
||||
builder
|
||||
.addCase(fetchTDRChartDataBySlotThunk.pending, (state) => {
|
||||
state.loading = true;
|
||||
state.error = null;
|
||||
})
|
||||
.addCase(
|
||||
fetchTDRChartDataBySlotThunk.fulfilled,
|
||||
(
|
||||
state,
|
||||
action: PayloadAction<{
|
||||
slot: number;
|
||||
data: { d: number; p: number }[];
|
||||
}>
|
||||
) => {
|
||||
const { slot, data } = action.payload;
|
||||
state.data[slot] = data;
|
||||
state.loading = false;
|
||||
}
|
||||
)
|
||||
.addCase(fetchTDRChartDataBySlotThunk.rejected, (state, action) => {
|
||||
state.loading = false;
|
||||
state.error = action.error.message ?? "Fehler beim Laden";
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
export default tdrSingleChartSlice.reducer;
|
||||
Reference in New Issue
Block a user