uninstall redux-persist, weil nimmt viel Performance weg
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
// /redux/slices/analogInputs/analogInputsHistory.ts
|
||||
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
||||
import { getAnalogInputsHistoryThunk } from "../thunks/getAnalogInputsHistoryThunk";
|
||||
import { getAnalogInputsHistoryThunk } from "../../thunks/getAnalogInputsHistoryThunk";
|
||||
|
||||
export type AnalogInputsHistoryEntry = {
|
||||
t: string;
|
||||
@@ -7,6 +8,7 @@ export type AnalogInputsHistoryEntry = {
|
||||
};
|
||||
|
||||
export interface InputHistoryState {
|
||||
selectedId: number | null;
|
||||
zeitraum: string;
|
||||
vonDatum: string;
|
||||
bisDatum: string;
|
||||
@@ -16,6 +18,7 @@ export interface InputHistoryState {
|
||||
}
|
||||
|
||||
const initialState: InputHistoryState = {
|
||||
selectedId: null,
|
||||
zeitraum: "DIA0",
|
||||
vonDatum: "",
|
||||
bisDatum: "",
|
||||
@@ -28,6 +31,9 @@ export const analogInputsHistorySlice = createSlice({
|
||||
name: "analogInputsHistory",
|
||||
initialState,
|
||||
reducers: {
|
||||
setSelectedId: (state, action: PayloadAction<number | null>) => {
|
||||
state.selectedId = action.payload;
|
||||
},
|
||||
setZeitraum: (state, action: PayloadAction<string>) => {
|
||||
state.zeitraum = action.payload;
|
||||
},
|
||||
@@ -56,7 +62,11 @@ export const analogInputsHistorySlice = createSlice({
|
||||
},
|
||||
});
|
||||
|
||||
export const { setZeitraum, setVonDatum, setBisDatum } =
|
||||
analogInputsHistorySlice.actions;
|
||||
export const {
|
||||
setSelectedId,
|
||||
setZeitraum,
|
||||
setVonDatum,
|
||||
setBisDatum,
|
||||
} = analogInputsHistorySlice.actions;
|
||||
|
||||
export default analogInputsHistorySlice.reducer;
|
||||
@@ -1,4 +1,4 @@
|
||||
// Redux Slice: redux/slices/analogInputsSlice.ts
|
||||
// Redux Slice: redux/slices/analogInputs/analogInputsSlice.ts
|
||||
import { createSlice, PayloadAction, createAsyncThunk } from "@reduxjs/toolkit";
|
||||
import type { AnalogInput } from "@/types/analogInput";
|
||||
|
||||
23
redux/slices/analogInputs/analogInputsUiSlice.ts
Normal file
23
redux/slices/analogInputs/analogInputsUiSlice.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
// /redux/slices/analogInputs/analogInputsUiSlice.ts
|
||||
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
||||
|
||||
interface AnalogInputsUiState {
|
||||
isSettingsModalOpen: boolean;
|
||||
}
|
||||
|
||||
const initialState: AnalogInputsUiState = {
|
||||
isSettingsModalOpen: false,
|
||||
};
|
||||
|
||||
const analogInputsUiSlice = createSlice({
|
||||
name: "analogInputsUi",
|
||||
initialState,
|
||||
reducers: {
|
||||
setIsSettingsModalOpen: (state, action: PayloadAction<boolean>) => {
|
||||
state.isSettingsModalOpen = action.payload;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const { setIsSettingsModalOpen } = analogInputsUiSlice.actions;
|
||||
export default analogInputsUiSlice.reducer;
|
||||
34
redux/slices/analogInputs/selectedAnalogInputSlice.ts
Normal file
34
redux/slices/analogInputs/selectedAnalogInputSlice.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
// redux/slices/analogInputs/selectedAnalogInputSlice.ts
|
||||
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
||||
import type { AnalogInput } from "@/types/analogInput";
|
||||
|
||||
// Anfangszustand: noch kein Eingang ausgewählt
|
||||
const initialState: AnalogInput = {
|
||||
id: 0,
|
||||
label: "",
|
||||
value: 0,
|
||||
name: "",
|
||||
};
|
||||
|
||||
const selectedAnalogInputSlice = createSlice({
|
||||
name: "selectedAnalogInput",
|
||||
initialState,
|
||||
reducers: {
|
||||
setSelectedAnalogInput(state, action: PayloadAction<AnalogInput>) {
|
||||
if (state) {
|
||||
// Mutiert vorhandene Struktur (optional, wenn initialState nicht null sein darf)
|
||||
Object.assign(state, action.payload);
|
||||
} else {
|
||||
return action.payload;
|
||||
}
|
||||
},
|
||||
clearSelectedAnalogInput() {
|
||||
return initialState;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const { setSelectedAnalogInput, clearSelectedAnalogInput } =
|
||||
selectedAnalogInputSlice.actions;
|
||||
|
||||
export default selectedAnalogInputSlice.reducer;
|
||||
@@ -1,29 +0,0 @@
|
||||
// /redux/slices/selectedAnalogInputSlice.ts
|
||||
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
||||
|
||||
type SelectedAnalogInput = {
|
||||
id: number;
|
||||
label: string;
|
||||
status: boolean;
|
||||
loggerInterval: number;
|
||||
};
|
||||
|
||||
const initialState: SelectedAnalogInput | null = null;
|
||||
// @ts-expect-error 123
|
||||
const selectedAnalogInputSlice = createSlice<SelectedAnalogInput | null>({
|
||||
name: "selectedAnalogInput",
|
||||
initialState,
|
||||
reducers: {
|
||||
setSelectedAnalogInput: (
|
||||
_state,
|
||||
action: PayloadAction<SelectedAnalogInput>
|
||||
) => action.payload,
|
||||
|
||||
resetSelectedAnalogInput: () => null,
|
||||
},
|
||||
});
|
||||
|
||||
export const { setSelectedAnalogInput, resetSelectedAnalogInput } =
|
||||
selectedAnalogInputSlice.actions;
|
||||
|
||||
export default selectedAnalogInputSlice.reducer;
|
||||
@@ -1,7 +1,5 @@
|
||||
// /redux/store.ts
|
||||
import { configureStore } from "@reduxjs/toolkit";
|
||||
import { persistReducer, persistStore } from "redux-persist";
|
||||
import storage from "redux-persist/lib/storage"; // = localStorage
|
||||
import authReducer from "./slices/authSlice";
|
||||
import kueChartModeReducer from "./slices/kueChartModeSlice";
|
||||
import webVersionReducer from "./slices/webVersionSlice";
|
||||
@@ -12,7 +10,7 @@ import opcuaSettingsReducer from "./slices/opcuaSettingsSlice";
|
||||
import digitalOutputsReducer from "./slices/digitalOutputsSlice";
|
||||
import brushReducer from "./slices/brushSlice";
|
||||
import tdrChartReducer from "./slices/tdrChartSlice";
|
||||
import analogInputsSlice from "./slices/analogInputsSlice";
|
||||
import analogInputsSlice from "./slices/analogInputs/analogInputsSlice";
|
||||
import digitalInputsReducer from "./slices/digitalInputsSlice";
|
||||
import tdrReferenceChartReducer from "./slices/tdrReferenceChartSlice";
|
||||
import loopChartReducer from "./slices/loopChartSlice";
|
||||
@@ -24,8 +22,8 @@ import tdmSingleChartReducer from "./slices/tdmSingleChartSlice";
|
||||
import tdrReferenceChartDataBySlotReducer from "./slices/tdrReferenceChartDataBySlotSlice";
|
||||
import loopChartTypeSlice from "./slices/loopChartTypeSlice";
|
||||
import systemVoltTempReducer from "./slices/systemVoltTempSlice";
|
||||
import analogInputsHistoryReducer from "./slices/analogInputsHistorySlice";
|
||||
import selectedAnalogInputReducer from "./slices/selectedAnalogInputSlice";
|
||||
import analogInputsHistoryReducer from "./slices/analogInputs/analogInputsHistorySlice";
|
||||
import selectedAnalogInputReducer from "./slices/analogInputs/selectedAnalogInputSlice";
|
||||
import messagesReducer from "./slices/messagesSlice";
|
||||
import firmwareUpdateReducer from "@/redux/slices/firmwareUpdateSlice";
|
||||
import confirmModalReducer from "./slices/confirmModalSlice";
|
||||
@@ -39,21 +37,7 @@ import temperaturProzessorReducer from "./slices/temperaturProzessorSlice";
|
||||
import { combineReducers } from "@reduxjs/toolkit";
|
||||
import { useDispatch, useSelector, TypedUseSelectorHook } from "react-redux";
|
||||
import systemChartReducer from "./slices/systemChartSlice";
|
||||
|
||||
//---------------------------------------
|
||||
// 🧠 Nur diese Slices werden persistiert
|
||||
const persistConfig = {
|
||||
key: "root",
|
||||
storage,
|
||||
whitelist: [
|
||||
"systemspannung5Vplus",
|
||||
"systemspannung15Vplus",
|
||||
"systemspannung15Vminus",
|
||||
"systemspannung98Vminus",
|
||||
"temperaturAdWandler",
|
||||
"temperaturProzessor",
|
||||
],
|
||||
};
|
||||
import analogInputsUiReducer from "./slices/analogInputs/analogInputsUiSlice";
|
||||
|
||||
const rootReducer = combineReducers({
|
||||
systemspannung5Vplus: systemspannung5VplusReducer,
|
||||
@@ -62,8 +46,6 @@ const rootReducer = combineReducers({
|
||||
systemspannung98Vminus: systemspannung98VminusReducer,
|
||||
temperaturAdWandler: temperaturAdWandlerReducer,
|
||||
temperaturProzessor: temperaturProzessorReducer,
|
||||
// Die restlichen Slices werden nicht persistiert, aber können hier auch aufgenommen werden,
|
||||
// falls sie Teil des globalen States sein sollen:
|
||||
authSlice: authReducer,
|
||||
kueChartModeSlice: kueChartModeReducer,
|
||||
webVersionSlice: webVersionReducer,
|
||||
@@ -73,7 +55,6 @@ const rootReducer = combineReducers({
|
||||
systemSettingsSlice: systemSettingsReducer,
|
||||
opcuaSettingsSlice: opcuaSettingsReducer,
|
||||
digitalOutputsSlice: digitalOutputsReducer,
|
||||
analogInputs: analogInputsSlice,
|
||||
brushSlice: brushReducer,
|
||||
tdrChartSlice: tdrChartReducer,
|
||||
tdrReferenceChartSlice: tdrReferenceChartReducer,
|
||||
@@ -86,30 +67,32 @@ const rootReducer = combineReducers({
|
||||
tdrReferenceChartDataBySlotSlice: tdrReferenceChartDataBySlotReducer,
|
||||
loopChartType: loopChartTypeSlice,
|
||||
systemVoltTemp: systemVoltTempReducer,
|
||||
analogInputsHistory: analogInputsHistoryReducer,
|
||||
selectedAnalogInput: selectedAnalogInputReducer,
|
||||
messages: messagesReducer,
|
||||
firmwareUpdate: firmwareUpdateReducer,
|
||||
confirmModal: confirmModalReducer,
|
||||
firmwareProgress: firmwareProgressReducer,
|
||||
systemChartSlice: systemChartReducer,
|
||||
analogInputs: analogInputsSlice,
|
||||
analogInputsHistory: analogInputsHistoryReducer,
|
||||
selectedAnalogInput: selectedAnalogInputReducer,
|
||||
analogInputsUi: analogInputsUiReducer,
|
||||
});
|
||||
// ⬆️ Alle deine Imports und combineReducers bleiben so wie du sie geschrieben hast ...
|
||||
|
||||
const persistedReducer = persistReducer(persistConfig, rootReducer);
|
||||
|
||||
//-------------------------------------------
|
||||
|
||||
// ✅ Store erstellen
|
||||
export const store = configureStore({
|
||||
reducer: persistedReducer,
|
||||
reducer: rootReducer,
|
||||
// (optional) middleware anpassen, z. B. um Warnungen zu ignorieren:
|
||||
middleware: (getDefaultMiddleware) =>
|
||||
getDefaultMiddleware({
|
||||
serializableCheck: false, // z. B. falls du redux-persist nutzt oder dispatch mit non-serializable Payloads hast
|
||||
}),
|
||||
});
|
||||
|
||||
export const persistor = persistStore(store);
|
||||
|
||||
// Typisierte Hooks
|
||||
// ✅ Typen für AppDispatch & RootState
|
||||
export type RootState = ReturnType<typeof store.getState>;
|
||||
export type AppDispatch = typeof store.dispatch;
|
||||
|
||||
export const useAppDispatch = () => useDispatch<AppDispatch>();
|
||||
// ✅ Hooks für Typsicherheit
|
||||
export const useAppDispatch: () => AppDispatch = useDispatch;
|
||||
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector;
|
||||
|
||||
export default store;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import { createAsyncThunk } from "@reduxjs/toolkit";
|
||||
import { fetchAnalogInputsHistory } from "@/services/fetchAnalogInputsHistoryService";
|
||||
import { AnalogInputsHistoryEntry } from "../slices/analogInputsHistorySlice";
|
||||
import { AnalogInputsHistoryEntry } from "@/redux/slices/analogInputs/analogInputsHistorySlice";
|
||||
|
||||
export const getAnalogInputsHistoryThunk = createAsyncThunk(
|
||||
"analogInputsHistory/fetch",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// /redux/thunks/getAnalogInputsThunk.ts
|
||||
import { createAsyncThunk } from "@reduxjs/toolkit";
|
||||
import { fetchAnalogInputsService } from "@/services/fetchAnalogInputsService";
|
||||
import { setAnalogInputs } from "@/redux/slices/analogInputsSlice";
|
||||
import { setAnalogInputs } from "@/redux/slices/analogInputs/analogInputsSlice";
|
||||
|
||||
/**
|
||||
* Holt die analogen Eingänge von der API und speichert sie in Redux.
|
||||
|
||||
Reference in New Issue
Block a user