Files
CPLv4.0/redux/slices/loopChartSlice.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

49 lines
1.1 KiB
TypeScript

// /redux/slices/loopChartSlice.ts
import { createSlice } from "@reduxjs/toolkit";
import { fetchLoopChartDataThunk } from "../thunks/fetchLoopChartDataThunk";
interface ChartData {
[mode: string]: {
[type: number]: any;
};
}
interface LoopChartState {
data: ChartData;
loading: boolean;
error: string | null;
}
const initialState: LoopChartState = {
data: {},
loading: false,
error: null,
};
const loopChartSlice = createSlice({
name: "loopChartSlice",
initialState,
reducers: {},
extraReducers: (builder) => {
builder
.addCase(fetchLoopChartDataThunk.pending, (state) => {
state.loading = true;
state.error = null;
})
.addCase(fetchLoopChartDataThunk.fulfilled, (state, action) => {
state.loading = false;
const { mode, type } = action.meta.arg;
if (!state.data[mode]) {
state.data[mode] = {};
}
state.data[mode][type] = action.payload;
})
.addCase(fetchLoopChartDataThunk.rejected, (state, action) => {
state.loading = false;
state.error = action.payload as string;
});
},
});
export default loopChartSlice.reducer;