Files
CPLv4.0/redux/slices/tdrDataByIdSlice.ts
ISA 20e20dec30 feat(redux): Rename all Redux slices and store keys to match file names for clarity
- 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
2025-04-01 12:26:41 +02:00

36 lines
1.1 KiB
TypeScript

// redux/slices/tdrDataByIdSlice.ts
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
import { fetchTDRChartDataByIdThunk } from "../thunks/fetchTDRChartDataByIdThunk";
const initialState = {
dataById: {} as Record<number, { d: number; p: number }[]>,
selectedId: null as number | null,
};
const tdrDataByIdSlice = createSlice({
name: "tdrDataByIdSlice",
initialState,
reducers: {
setTDRChartDataById: (
state,
action: PayloadAction<{ id: number; data: { d: number; p: number }[] }>
) => {
state.dataById[action.payload.id] = action.payload.data;
},
setSelectedTDRId: (state, action: PayloadAction<number>) => {
state.selectedId = action.payload;
},
},
extraReducers: (builder) => {
builder.addCase(fetchTDRChartDataByIdThunk.fulfilled, (state, action) => {
const { id, data } = action.payload;
state.dataById[id] = data;
state.selectedId = id;
});
},
});
export const { setTDRChartDataById, setSelectedTDRId } =
tdrDataByIdSlice.actions;
export default tdrDataByIdSlice.reducer;