Files
CPLv4.0/redux/thunks/fetchAllTDMThunk.ts
2025-04-02 08:14:17 +02:00

24 lines
740 B
TypeScript

// /redux/thunks/fetchAllTDMThunk.ts
import { createAsyncThunk } from "@reduxjs/toolkit";
import { RootState } from "../store";
import { fetchAllTDMDataFromServer } from "../../services/fetchAllTDMData";
export const fetchAllTDMData = createAsyncThunk(
"tdmChart/fetchAllTDMData",
async (_, { getState, rejectWithValue }) => {
const currentData = (getState() as RootState).tdmChartSlice.data;
const newData = await fetchAllTDMDataFromServer();
if (newData.every((entry) => !entry)) {
return rejectWithValue("Keine TDM-Daten empfangen.");
}
if (JSON.stringify(currentData) !== JSON.stringify(newData)) {
return newData;
}
return rejectWithValue("Keine Änderungen in den TDM-Daten.");
}
);