- Globalen fetchAllTDRChartData entfernt - Neuen Slice und Thunk pro Slot erstellt - TDRChart liest initiale Daten aus neuem Slice
54 lines
1.3 KiB
TypeScript
54 lines
1.3 KiB
TypeScript
// 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;
|