'use client'; import { useEffect, useState } from 'react'; import ReactMarkdown from 'react-markdown'; interface NewsItem { id: number; title: string; content: string; author: string | null; publishedAt: string; featured: boolean; special: { id: number; name: string; } | null; } export default function NewsSection() { const [news, setNews] = useState([]); const [isExpanded, setIsExpanded] = useState(false); const [loading, setLoading] = useState(true); useEffect(() => { fetchNews(); }, []); const fetchNews = async () => { try { const res = await fetch('/api/news?limit=3'); if (res.ok) { const data = await res.json(); setNews(data); } } catch (error) { console.error('Failed to fetch news:', error); } finally { setLoading(false); } }; if (loading || news.length === 0) { return null; // Don't show anything if no news } return (
{/* Header */} {/* Content */} {isExpanded && (
{news.map((item, index) => (
{/* Title */}
{item.featured && ( ⭐ FEATURED )}

{item.title}

{/* Metadata */}
{new Date(item.publishedAt).toLocaleDateString('de-DE', { day: '2-digit', month: '2-digit', year: 'numeric' })} {item.author && ( <> by {item.author} )} {item.special && ( <> ★ {item.special.name} )}
{/* Content */}

{children}

, a: ({ children, href }) => ( {children} ), strong: ({ children }) => {children}, em: ({ children }) => {children}, ul: ({ children }) =>
    {children}
, ol: ({ children }) =>
    {children}
, li: ({ children }) =>
  • {children}
  • }} > {item.content}
    ))}
    )}
    ); }