feat: Redux-Integration für Meldungen, Anzeige von 'v' statt 's' in UI
This commit is contained in:
BIN
redux/slices.zip
BIN
redux/slices.zip
Binary file not shown.
47
redux/slices/messagesSlice.ts
Normal file
47
redux/slices/messagesSlice.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
// redux/slices/messagesSlice.ts
|
||||
import { createSlice } from "@reduxjs/toolkit";
|
||||
import { getMessagesThunk } from "../thunks/getMessagesThunk";
|
||||
|
||||
type Meldung = {
|
||||
t: string;
|
||||
s: number;
|
||||
c: string;
|
||||
m: string;
|
||||
i: string;
|
||||
v: string;
|
||||
};
|
||||
|
||||
interface MessagesState {
|
||||
data: Meldung[];
|
||||
loading: boolean;
|
||||
error: string | null;
|
||||
}
|
||||
|
||||
const initialState: MessagesState = {
|
||||
data: [],
|
||||
loading: false,
|
||||
error: null,
|
||||
};
|
||||
|
||||
const messagesSlice = createSlice({
|
||||
name: "messages",
|
||||
initialState,
|
||||
reducers: {},
|
||||
extraReducers: (builder) => {
|
||||
builder
|
||||
.addCase(getMessagesThunk.pending, (state) => {
|
||||
state.loading = true;
|
||||
state.error = null;
|
||||
})
|
||||
.addCase(getMessagesThunk.fulfilled, (state, action) => {
|
||||
state.loading = false;
|
||||
state.data = action.payload;
|
||||
})
|
||||
.addCase(getMessagesThunk.rejected, (state, action) => {
|
||||
state.loading = false;
|
||||
state.error = action.error.message ?? "Unbekannter Fehler";
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
export default messagesSlice.reducer;
|
||||
Binary file not shown.
@@ -25,6 +25,7 @@ import loopChartTypeSlice from "./slices/loopChartTypeSlice";
|
||||
import systemVoltTempReducer from "./slices/systemVoltTempSlice";
|
||||
import analogInputsHistoryReducer from "./slices/analogInputsHistorySlice";
|
||||
import selectedAnalogInputReducer from "./slices/selectedAnalogInputSlice";
|
||||
import messagesReducer from "./slices/messagesSlice";
|
||||
|
||||
const store = configureStore({
|
||||
reducer: {
|
||||
@@ -52,6 +53,7 @@ const store = configureStore({
|
||||
systemVoltTemp: systemVoltTempReducer,
|
||||
analogInputsHistory: analogInputsHistoryReducer,
|
||||
selectedAnalogInput: selectedAnalogInputReducer,
|
||||
messages: messagesReducer,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
BIN
redux/thunks.zip
BIN
redux/thunks.zip
Binary file not shown.
10
redux/thunks/getMessagesThunk.ts
Normal file
10
redux/thunks/getMessagesThunk.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
// redux/thunks/getMessagesThunk.ts
|
||||
import { createAsyncThunk } from "@reduxjs/toolkit";
|
||||
import { fetchMessagesService } from "@/services/fetchMessagesService";
|
||||
|
||||
export const getMessagesThunk = createAsyncThunk(
|
||||
"messages/getAll",
|
||||
async ({ fromDate, toDate }: { fromDate: string; toDate: string }) => {
|
||||
return await fetchMessagesService(fromDate, toDate);
|
||||
}
|
||||
);
|
||||
BIN
redux/types.zip
BIN
redux/types.zip
Binary file not shown.
Reference in New Issue
Block a user