fix: Firmware-Update läuft nun exakt 5 Minuten bis 100 % Fortschritt
- Fehler behoben, bei dem das Firmware-Update nach wenigen Sekunden vorzeitig beendet wurde - Fortschrittsanzeige über Redux-Slice `firmwareProgressSlice` korrekt umgesetzt - Thunk `startFirmwareUpdateThunk` korrekt eingebunden und verwendet - UI zeigt stabile 5-minütige Progressbar wie erwartet
This commit is contained in:
28
redux/slices/firmwareProgressSlice.ts
Normal file
28
redux/slices/firmwareProgressSlice.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
// redux/slices/firmwareProgressSlice.ts
|
||||
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
||||
|
||||
interface State {
|
||||
progress: number;
|
||||
isUpdating: boolean;
|
||||
}
|
||||
|
||||
const initialState: State = {
|
||||
progress: 0,
|
||||
isUpdating: false,
|
||||
};
|
||||
|
||||
export const firmwareProgressSlice = createSlice({
|
||||
name: "firmwareProgress",
|
||||
initialState,
|
||||
reducers: {
|
||||
setProgress: (state, action: PayloadAction<number>) => {
|
||||
state.progress = action.payload;
|
||||
},
|
||||
setIsUpdating: (state, action: PayloadAction<boolean>) => {
|
||||
state.isUpdating = action.payload;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const { setProgress, setIsUpdating } = firmwareProgressSlice.actions;
|
||||
export default firmwareProgressSlice.reducer;
|
||||
@@ -28,6 +28,7 @@ import selectedAnalogInputReducer from "./slices/selectedAnalogInputSlice";
|
||||
import messagesReducer from "./slices/messagesSlice";
|
||||
import firmwareUpdateReducer from "@/redux/slices/firmwareUpdateSlice";
|
||||
import confirmModalReducer from "./slices/confirmModalSlice";
|
||||
import firmwareProgressReducer from "./slices/firmwareProgressSlice";
|
||||
|
||||
const store = configureStore({
|
||||
reducer: {
|
||||
@@ -58,6 +59,7 @@ const store = configureStore({
|
||||
messages: messagesReducer,
|
||||
firmwareUpdate: firmwareUpdateReducer,
|
||||
confirmModal: confirmModalReducer,
|
||||
firmwareProgress: firmwareProgressReducer,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
31
redux/thunks/startFirmwareUpdateThunk.ts
Normal file
31
redux/thunks/startFirmwareUpdateThunk.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
// redux/thunks/startFirmwareUpdateThunk.ts
|
||||
import { AppDispatch } from "../store";
|
||||
import {
|
||||
setProgress,
|
||||
setIsUpdating,
|
||||
} from "@/redux/slices/firmwareProgressSlice";
|
||||
|
||||
export const startFirmwareUpdateThunk =
|
||||
(slot: number) => async (dispatch: AppDispatch) => {
|
||||
dispatch(setIsUpdating(true));
|
||||
dispatch(setProgress(0));
|
||||
|
||||
const totalDuration = 5 * 60 * 1000;
|
||||
const intervalMs = 1000;
|
||||
const steps = totalDuration / intervalMs;
|
||||
let currentStep = 0;
|
||||
|
||||
const interval = setInterval(() => {
|
||||
currentStep++;
|
||||
const percent = Math.min((currentStep / steps) * 100, 100);
|
||||
dispatch(setProgress(percent));
|
||||
|
||||
if (currentStep >= steps) {
|
||||
clearInterval(interval);
|
||||
dispatch(setProgress(100));
|
||||
setTimeout(() => {
|
||||
dispatch(setIsUpdating(false));
|
||||
}, 500);
|
||||
}
|
||||
}, intervalMs);
|
||||
};
|
||||
Reference in New Issue
Block a user