42 lines
1.1 KiB
TypeScript
42 lines
1.1 KiB
TypeScript
// /redux/slices/analogInputsHistorySlice.ts
|
|
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
|
import { getAnalogInputsHistoryThunk } from "../thunks/getAnalogInputsHistoryThunk";
|
|
|
|
type InputHistoryState = {
|
|
data: Record<number, any[]>;
|
|
isLoading: boolean;
|
|
error: string | null;
|
|
};
|
|
|
|
const initialState: InputHistoryState = {
|
|
data: {},
|
|
isLoading: false,
|
|
error: null,
|
|
};
|
|
|
|
const analogInputsHistorySlice = createSlice({
|
|
name: "analogInputsHistory",
|
|
initialState,
|
|
reducers: {},
|
|
extraReducers: (builder) => {
|
|
builder
|
|
.addCase(getAnalogInputsHistoryThunk.pending, (state) => {
|
|
state.isLoading = true;
|
|
state.error = null;
|
|
})
|
|
.addCase(
|
|
getAnalogInputsHistoryThunk.fulfilled,
|
|
(state, action: PayloadAction<Record<number, any[]>>) => {
|
|
state.data = action.payload;
|
|
state.isLoading = false;
|
|
}
|
|
)
|
|
.addCase(getAnalogInputsHistoryThunk.rejected, (state, action) => {
|
|
state.isLoading = false;
|
|
state.error = action.payload as string;
|
|
});
|
|
},
|
|
});
|
|
|
|
export default analogInputsHistorySlice.reducer;
|