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);
|
||||
};
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
// /services/fetchTDRChartData.ts
|
||||
|
||||
export const fetchTDRChartData = async (
|
||||
selectedFileName: string | null
|
||||
): Promise<any | null> => {
|
||||
if (!selectedFileName) {
|
||||
console.error("Kein Dateiname in Redux gespeichert.");
|
||||
return null;
|
||||
}
|
||||
|
||||
const yearFolder = `Year_${new Date().getFullYear().toString().slice(-2)}`;
|
||||
const monthFolder = `Month_${(new Date().getMonth() + 1)
|
||||
.toString()
|
||||
.padStart(2, "0")}`;
|
||||
|
||||
// const filePath = `/CPLmockData/LastTDR/kue_01/${yearFolder}/${monthFolder}/${selectedFileName}`;
|
||||
const filePath = `/CPLmockData/LastTDR/jsonDatei/${selectedFileName}`;
|
||||
|
||||
try {
|
||||
const response = await fetch(filePath);
|
||||
if (!response.ok) {
|
||||
throw new Error(
|
||||
`Fehler beim Laden der TDR-Daten: ${response.statusText}`
|
||||
);
|
||||
}
|
||||
const data = await response.json();
|
||||
console.log("Geladene TDR-Daten:", data);
|
||||
return data;
|
||||
} catch (error) {
|
||||
console.error("Fehler beim Laden der TDR-Daten:", error);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user