Files
CPLv4.0/redux/slices/tdmChartSlice.ts

43 lines
1.0 KiB
TypeScript

// /redux/slices/tdmChartSlice.ts
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
import { fetchAllTDMData } from "../thunks/getAllTDMThunk";
import type { TDMEntry } from "../types/tdmEntryTypes";
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: "tdmChartSlice",
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;