100 lines
3.5 KiB
JavaScript
100 lines
3.5 KiB
JavaScript
"use client";
|
|
import React, { useEffect, useState } from "react";
|
|
import Image from "next/image";
|
|
import "bootstrap-icons/font/bootstrap-icons.css";
|
|
|
|
function Header() {
|
|
const [stationsname, setStationsname] = useState("Lädt..."); // Platzhalter
|
|
const [cplStatus, setCplStatus] = useState("Lädt...");
|
|
|
|
useEffect(() => {
|
|
// API-Aufruf, um die Daten vom Server zu holen
|
|
fetch("http://localhost:3000/api/server?path=main.js", { mode: "cors" })
|
|
.then((response) => {
|
|
if (!response.ok) {
|
|
throw new Error("Fehler beim Abrufen der Daten");
|
|
}
|
|
return response.text(); // Holen des gesamten Textinhalts
|
|
})
|
|
.then((data) => {
|
|
console.log("Fetched data:", data); // Logge die empfangenen Daten
|
|
const parsedData = extractDataFromFile(data);
|
|
setStationsname(parsedData.stationsname);
|
|
setCplStatus(parsedData.cplStatus);
|
|
})
|
|
.catch((error) => {
|
|
console.error("Fehler beim Abrufen der Daten:", error);
|
|
});
|
|
}, []);
|
|
|
|
// Funktion zum Extrahieren der gewünschten Daten aus dem Text
|
|
function extractDataFromFile(fileText) {
|
|
// Beispiel zum Extrahieren des Stationsnamens, du kannst dies nach Bedarf anpassen
|
|
const stationsnameMatch = fileText.match(/<h1>Willkommen bei (.*?)<\/h1>/);
|
|
const cplStatusMatch = fileText.match(/<p>Hardware Version: (.*?)<\/p>/);
|
|
|
|
return {
|
|
stationsname: stationsnameMatch ? stationsnameMatch[1] : "Unbekannt",
|
|
cplStatus: cplStatusMatch ? cplStatusMatch[1] : "Unbekannt",
|
|
};
|
|
}
|
|
|
|
return (
|
|
<header className="bg-gray-300 flex justify-between items-center w-full h-28 p-4">
|
|
<div className="relative w-1/4 h-full">
|
|
<Image
|
|
src="/images/Logo.png"
|
|
alt="Logo"
|
|
fill
|
|
style={{ objectFit: "contain" }}
|
|
className="absolute -bottom-8 transform translate-y-1/2"
|
|
priority={false}
|
|
/>
|
|
</div>
|
|
|
|
{/* CPL Status und Stationsname */}
|
|
<div className="flex items-center space-x-4 w-full justify-center">
|
|
<div className="flex flex-col text-left">
|
|
<h2 className="text-sm font-semibold">Stationsname</h2>
|
|
<p className="font-bold text-lg">{stationsname}</p>
|
|
</div>
|
|
<div className="flex flex-col text-left">
|
|
<p className="text-sm font-medium">CPL Status</p>
|
|
<span className="text-green-500 font-bold">{cplStatus}</span>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Temperatur und Icons */}
|
|
<div className="flex items-center space-x-4 w-1/4 justify-end">
|
|
{/* Temperatur und Luftfeuchtigkeit */}
|
|
<div className="hidden sm:flex items-center space-x-4">
|
|
<div className="flex items-center">
|
|
<i className="bi bi-thermometer-half"></i>
|
|
<p className="text-lg ml-1">20.5 °C</p>
|
|
</div>
|
|
<div className="flex items-center">
|
|
<i className="bi bi-droplet"></i>
|
|
<p className="text-lg ml-1">60%</p>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Toggle Switch light and dark mode */}
|
|
<div className="hidden sm:flex items-center space-x-4">
|
|
<i className="bi bi-moon"></i>
|
|
<div className="flex items-center space-x-2">
|
|
<i className="bi bi-toggle-off"></i>
|
|
<i className="bi bi-brightness-high"></i>
|
|
</div>
|
|
</div>
|
|
|
|
{/* User Icon */}
|
|
<div className="flex items-center">
|
|
<i className="bi bi-person-circle text-3xl text-black"></i>
|
|
</div>
|
|
</div>
|
|
</header>
|
|
);
|
|
}
|
|
|
|
export default Header;
|