"use client"; // /pages/meldungen.tsx import React, { useState } from "react"; type Meldung = { t: string; s: number; c: string; m: string; i: string; }; const ITEMS_PER_PAGE = 10; export default function Messages() { const [messages, setMessages] = useState([]); const [currentPage, setCurrentPage] = useState(1); // Datum initialisieren: von = heute - 30 Tage, bis = heute const today = new Date(); const prior30 = new Date(); prior30.setDate(today.getDate() - 30); const formatDate = (d: Date) => d.toISOString().split("T")[0]; const [fromDate, setFromDate] = useState(formatDate(prior30)); const [toDate, setToDate] = useState(formatDate(today)); const fetchMessages = async () => { const from = new Date(fromDate); const to = new Date(toDate); const fy = from.getFullYear(); const fm = String(from.getMonth() + 1).padStart(2, "0"); const fd = String(from.getDate()).padStart(2, "0"); const ty = to.getFullYear(); const tm = String(to.getMonth() + 1).padStart(2, "0"); const td = String(to.getDate()).padStart(2, "0"); const isDev = typeof window !== "undefined" && window.location.hostname === "localhost"; const url = isDev ? `/api/cpl/messages?MSS1=${fy};${fm};${fd};${ty};${tm};${td};All` : `/CPL?Service/ae.ACP&MSS1=${fy};${fm};${fd};${ty};${tm};${td};All`; try { const res = await fetch(url); const raw = await res.json(); console.log("URL:", url); console.log("Daten vom Server:", raw); const data = Array.isArray(raw) ? raw : raw.data; if (!Array.isArray(data)) { console.error("Die empfangenen Daten sind kein Array:", data); return; } setMessages(data); setCurrentPage(1); } catch (err) { console.error("Fehler beim Laden der Meldungen:", err); } }; const totalPages = Math.ceil(messages.length / ITEMS_PER_PAGE); const currentMessages = messages.slice( (currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE ); return (

Meldungen

setFromDate(e.target.value)} className="border px-2 py-1 rounded" />
setToDate(e.target.value)} className="border px-2 py-1 rounded" />
{currentMessages.map((msg, index) => ( ))}
Status Zeitstempel Gewicht Text Quelle
{msg.t} {msg.s} {msg.m} {msg.i}
{messages.length === 0 && (
Keine Meldungen im gewählten Zeitraum vorhanden.
)}
Seite {currentPage} von {totalPages}
); }