import { useQuery } from "@tanstack/react-query"; import { useState, useEffect, useCallback } from "react"; import { Newspaper, ExternalLink } from "lucide-react"; interface NewsItem { title: string; link: string; source: string; pubDate: string; } const VISIBLE_COUNT = 5; export function NewsWidget() { const { data: news, isLoading } = useQuery({ queryKey: ["/api/news-feed"], }); const [offset, setOffset] = useState(0); const [paused, setPaused] = useState(false); const items = news || []; const total = items.length; const advance = useCallback(() => { if (total <= VISIBLE_COUNT) return; setOffset((o) => (o + 1) % total); }, [total]); useEffect(() => { if (paused || total <= VISIBLE_COUNT) return; const timer = setInterval(advance, 5000); return () => clearInterval(timer); }, [paused, advance, total]); const visible: NewsItem[] = []; for (let i = 0; i < Math.min(VISIBLE_COUNT, total); i++) { visible.push(items[(offset + i) % total]); } return (
setPaused(true)} onMouseLeave={() => setPaused(false)} data-testid="widget-news" >

Musiknachrichten

{visible.map((item, i) => (

{item.title}

{item.source} {item.pubDate}
{i < VISIBLE_COUNT - 1 &&
} ))} {isLoading && (
{Array.from({ length: VISIBLE_COUNT }).map((_, i) => (
{i < VISIBLE_COUNT - 1 &&
}
))}
)} {!isLoading && total === 0 && (

Keine Nachrichten verfügbar

)}
); }