- Renamed all slice names (createSlice `name` attribute) to match their file names (e.g. loopChartSlice, authSlice, kueDataSlice etc.) - Updated `store.ts` to register each reducer with consistent key names (e.g. state.loopChartSlice instead of state.loopChart) - Adjusted all `useSelector` and Redux state accesses across the codebase - Improves maintainability, searchability and consistency across files and Redux DevTools
42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
// /redux/slices/tdrReferenceChartDataBySlotSlice.ts
|
|
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
|
import { fetchReferenceCurveBySlotThunk } from "../thunks/fetchReferenceCurveBySlotThunk";
|
|
|
|
interface TDRReferenceChartState {
|
|
referenceData: { [slot: number]: any[] };
|
|
loading: boolean;
|
|
error: string | null;
|
|
}
|
|
|
|
const initialState: TDRReferenceChartState = {
|
|
referenceData: {},
|
|
loading: false,
|
|
error: null,
|
|
};
|
|
|
|
const tdrReferenceChartDataBySlotSlice = createSlice({
|
|
name: "tdrReferenceChartDataBySlotSlice",
|
|
initialState,
|
|
reducers: {},
|
|
extraReducers: (builder) => {
|
|
builder
|
|
.addCase(fetchReferenceCurveBySlotThunk.pending, (state) => {
|
|
state.loading = true;
|
|
state.error = null;
|
|
})
|
|
.addCase(
|
|
fetchReferenceCurveBySlotThunk.fulfilled,
|
|
(state, action: PayloadAction<{ slot: number; data: any[] }>) => {
|
|
state.loading = false;
|
|
state.referenceData[action.payload.slot] = action.payload.data;
|
|
}
|
|
)
|
|
.addCase(fetchReferenceCurveBySlotThunk.rejected, (state, action) => {
|
|
state.loading = false;
|
|
state.error = action.error.message ?? "Unbekannter Fehler";
|
|
});
|
|
},
|
|
});
|
|
|
|
export default tdrReferenceChartDataBySlotSlice.reducer;
|