feat: TDR-Chart mit Tooltip und Pegel-Darstellung hinzugefügt
This commit is contained in:
@@ -1,21 +1,21 @@
|
||||
// /services/fetchAllTDRChartData.ts
|
||||
import { Dispatch } from "@reduxjs/toolkit";
|
||||
import { setTDRData, selectTDRData } from "../redux/slices/tdrChartSlice";
|
||||
import { RootState } from "../redux/store";
|
||||
|
||||
const BASE_PATH = "/CPLmockData/LastTDR/jsonDatei";
|
||||
const getTDRBasePath = () => {
|
||||
if (typeof window !== "undefined") {
|
||||
return window.location.hostname === "localhost"
|
||||
? "/CPLmockData/LastTDR/jsonDatei"
|
||||
: "/CPL?/CPL/LastTDR";
|
||||
}
|
||||
return "";
|
||||
};
|
||||
|
||||
export const fetchAllTDRChartData = async (
|
||||
dispatch: Dispatch,
|
||||
getState: () => RootState
|
||||
) => {
|
||||
const state = getState();
|
||||
const currentData = selectTDRData(state);
|
||||
export const fetchAllTDRChartDataFromServer = async (): Promise<any[]> => {
|
||||
const basePath = getTDRBasePath();
|
||||
const fileNames = Array.from({ length: 32 }, (_, i) => `slot${i}.json`);
|
||||
|
||||
const fileNames = Array.from({ length: 32 }, (_, i) => `json${i}`);
|
||||
const fetchPromises = fileNames.map(async (fileName) => {
|
||||
try {
|
||||
const response = await fetch(`${BASE_PATH}/${fileName}.json`);
|
||||
const response = await fetch(`${basePath}/${fileName}`);
|
||||
if (!response.ok)
|
||||
throw new Error(`Fehler bei ${fileName}: ${response.statusText}`);
|
||||
return await response.json();
|
||||
@@ -25,10 +25,5 @@ export const fetchAllTDRChartData = async (
|
||||
}
|
||||
});
|
||||
|
||||
const newData = await Promise.all(fetchPromises);
|
||||
|
||||
// Nur aktualisieren, wenn sich die Daten geändert haben
|
||||
if (JSON.stringify(currentData) !== JSON.stringify(newData)) {
|
||||
dispatch(setTDRData(newData));
|
||||
}
|
||||
return await Promise.all(fetchPromises);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user