"use client"; import React, { useEffect, useState } from "react"; type Meldung = { t: string; // Zeitstempel s: number; // Status c: string; // Farbe m: string; // Meldung i: string; // Modul/Quelle }; const Last20MessagesTable: React.FC<{ className?: string }> = ({ className, }) => { const [messages, setMessages] = useState([]); useEffect(() => { const fetchLast20Messages = async () => { const today = new Date(); const prior30 = new Date(); prior30.setDate(today.getDate() - 30); const format = (d: Date) => `${d.getFullYear()};${(d.getMonth() + 1) .toString() .padStart(2, "0")};${d.getDate().toString().padStart(2, "0")}`; const from = format(prior30); const to = format(today); const isDev = typeof window !== "undefined" && window.location.hostname === "localhost"; const url = isDev ? `/api/cpl/last20MessagesAPIHandler` : `/CPL?Service/ae.ACP&MSS1=${from};${to};All`; try { const res = await fetch(url); const raw = await res.json(); const data = Array.isArray(raw) ? raw : raw.data; if (!Array.isArray(data)) return; const sorted = [...data].sort( (a, b) => new Date(b.t).getTime() - new Date(a.t).getTime() ); const last20 = sorted.slice(0, 20); // NEUESTE zuerst setMessages(last20); } catch (err) { console.error("Fehler beim Laden der Meldungen:", err); } }; fetchLast20Messages(); }, []); return (
{messages.length === 0 ? ( ) : ( messages.map((msg, index) => ( )) )}
Prio Zeit Quelle Meldung Status
Keine Meldungen verfügbar.
{msg.t} {msg.i} {msg.m} {msg.s}
); }; export default Last20MessagesTable;