// /pages/meldungen.tsx "use client"; import React, { useEffect, 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); const [fromDate, setFromDate] = useState( () => new Date().toISOString().split("T")[0] ); const [toDate, setToDate] = useState( () => new Date().toISOString().split("T")[0] ); 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 ? "/CPLmockData/meldungen/messages.json" : `/CPL?Service/ae.ACP&MSS1=${fy};${fm};${fd};${ty};${tm};${td};All`; try { const res = await fetch(url); const data = await res.json(); setMessages(data); setCurrentPage(1); } catch (err) { console.error("Fehler beim Laden der Meldungen:", err); } }; useEffect(() => { fetchMessages(); }, []); 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}
Seite {currentPage} von {totalPages}
); }