import { useQuery } from "@tanstack/react-query"; import { useParams, Link, useLocation, useSearch } from "wouter"; import { type Article } from "@shared/schema"; import { format } from "date-fns"; import { de } from "date-fns/locale"; import { usePageMeta } from "@/hooks/use-page-meta"; import { Eye, ArrowLeft, ChevronLeft, ChevronRight } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Skeleton } from "@/components/ui/skeleton"; import Header from "@/components/header"; import Footer from "@/components/footer"; import { ArticleCardAd, PageSideAds, TopBannerAd, MultiplexAd } from "@/components/adsense"; import { useEffect } from "react"; interface PaginatedResponse { articles: Article[]; total: number; page: number; totalPages: number; hasMore: boolean; } export default function CategoryPage() { const { category } = useParams<{ category: string }>(); const searchString = useSearch(); const [, setLocation] = useLocation(); const searchParams = new URLSearchParams(searchString); const currentPage = Math.max(1, parseInt(searchParams.get("page") || "1")); usePageMeta( `${category}${currentPage > 1 ? ` – Seite ${currentPage}` : ""} - Volksmusik & Schlager`, `Aktuelle ${category}-Beiträge und Nachrichten aus der Volksmusik- und Schlagerszene. Neueste Volksmusik-Meldungen bei FOLX TV.` ); const { data, isLoading } = useQuery({ queryKey: ["/api/articles/category", category, { page: currentPage }], queryFn: async () => { const res = await fetch(`/api/articles/category/${category}?page=${currentPage}&limit=12`); if (!res.ok) throw new Error("Failed to fetch articles"); return res.json(); }, }); useEffect(() => { window.scrollTo({ top: 0, behavior: "smooth" }); }, [currentPage]); const goToPage = (page: number) => { if (page === 1) { setLocation(`/category/${category}`); } else { setLocation(`/category/${category}?page=${page}`); } }; const renderPagination = () => { if (!data || data.totalPages <= 1) return null; const pages: (number | string)[] = []; const total = data.totalPages; const current = data.page; pages.push(1); if (current > 3) pages.push("..."); for (let i = Math.max(2, current - 1); i <= Math.min(total - 1, current + 1); i++) { pages.push(i); } if (current < total - 2) pages.push("..."); if (total > 1) pages.push(total); return ( ); }; return (

{category}

{data && data.total > 0 && ( {data.total} Beiträge {data.totalPages > 1 && ` · Seite ${data.page} von ${data.totalPages}`} )}
{isLoading ? (
{Array.from({ length: 6 }).map((_, i) => (
))}
) : data && data.articles.length > 0 ? ( <>
{(() => { const items: React.ReactNode[] = []; const articles = data.articles; let ai = 0; let row = 0; while (ai < articles.length) { const adCol = row % 4; for (let col = 0; col < 4; col++) { if (col === adCol) { items.push(); } else if (ai < articles.length) { const a = articles[ai]; items.push(
{a.title}

{a.title}

{format(new Date(a.publishedAt), "d. MMMM yyyy", { locale: de })}
); ai++; } } row++; } return items; })()}
{renderPagination()} ) : (

Keine Artikel in dieser Kategorie gefunden.

)}
Anzeige
); }