Files
CPLv4.0/redux/thunks/getAllTDRChartThunk.ts

36 lines
1.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// /redux/thunks/getAllTDRChartThunk.ts
import { createAsyncThunk } from "@reduxjs/toolkit";
import { RootState } from "../store";
import isEqual from "lodash/isEqual";
import { fetchAllTDRChartDataFromServer } from "@/services/fetchAllTDRChartDataService"; // ✅ importieren
export const fetchAllTDRChartData = createAsyncThunk(
"tdrChart/fetchAllTDRChartData",
async (_, { getState, rejectWithValue }) => {
const state = getState() as RootState;
const currentData = state.tdrChartSlice.data;
const newData = await fetchAllTDRChartDataFromServer(); // ✅ Service aufrufen
if (newData.every((d) => d === null || d === undefined)) {
console.warn("⚠ Keine gültigen Daten empfangen.");
return rejectWithValue("Keine gültigen Daten empfangen.");
}
if (
!isEqual(
JSON.parse(JSON.stringify(currentData)),
JSON.parse(JSON.stringify(newData))
) ||
currentData.length === 0
) {
console.log("🔥 Neue Daten erkannt Redux wird aktualisiert.");
return newData;
} else {
console.log("⚠ Keine signifikanten Änderungen erkannt.");
return rejectWithValue("Keine Änderungen in den Daten.");
}
}
);