57 lines
1.4 KiB
TypeScript
57 lines
1.4 KiB
TypeScript
"use client"; // hooks/einausgaenge/useDigitalInputsData.ts
|
|
import { useEffect, useState } from "react";
|
|
|
|
export function useDigitalInputData() {
|
|
const [mockData, setMockData] = useState({
|
|
win_de: Array(32).fill(0),
|
|
win_counter: Array(32).fill(0),
|
|
win_flutter: Array(32).fill(0),
|
|
});
|
|
const [isLoading, setIsLoading] = useState(true);
|
|
|
|
useEffect(() => {
|
|
const isDevelopment = process.env.NODE_ENV === "development";
|
|
const script = document.createElement("script");
|
|
|
|
script.src = isDevelopment
|
|
? "/CPLmockData/SERVICE/de.js"
|
|
: "/CPL/SERVICE/de.js";
|
|
script.async = true;
|
|
|
|
script.onload = () => {
|
|
try {
|
|
if (
|
|
typeof win_de !== "undefined" &&
|
|
typeof win_counter !== "undefined" &&
|
|
typeof win_flutter !== "undefined"
|
|
) {
|
|
setMockData({
|
|
win_de,
|
|
win_counter,
|
|
win_flutter,
|
|
});
|
|
} else {
|
|
console.error("Mock-Daten konnten nicht geladen werden.");
|
|
}
|
|
} catch (error) {
|
|
console.error("Fehler beim Zugriff auf die globalen Daten:", error);
|
|
} finally {
|
|
setIsLoading(false);
|
|
}
|
|
};
|
|
|
|
script.onerror = () => {
|
|
console.error("Fehler beim Laden der Skript-Datei:", script.src);
|
|
setIsLoading(false);
|
|
};
|
|
|
|
document.body.appendChild(script);
|
|
|
|
return () => {
|
|
document.body.removeChild(script);
|
|
};
|
|
}, []);
|
|
|
|
return { mockData, isLoading };
|
|
}
|