Files
CPLv4.0/redux/thunks/fetchAnalogInputsThunk.ts
2025-06-19 12:27:00 +02:00

23 lines
808 B
TypeScript

// /redux/thunks/fetchAnalogInputsThunk.ts
import { createAsyncThunk } from "@reduxjs/toolkit";
import { fetchAnalogInputsService } from "@/services/fetchAnalogInputsService";
import { setAnalogInputs } from "@/redux/slices/analogInputsSlice";
/**
* Holt die analogen Eingänge von der API und speichert sie in Redux.
*/
export const fetchAnalogInputsThunk = createAsyncThunk(
"analogeInputs/fetchAnalogInputs",
async (_, { dispatch }) => {
if (typeof window === "undefined") return; // Server-Side Execution blockieren
try {
const data = await fetchAnalogInputsService();
if (data) {
dispatch(setAnalogInputs(data)); // ✅ Redux mit API-Daten füllen
}
} catch (error) {
console.error("❌ Fehler beim Laden der analogen Eingänge:", error);
}
}
);