import { useQuery } from "@tanstack/react-query";
import { 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 { Play, 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 } from "@/components/adsense";
import { useEffect } from "react";
interface PaginatedResponse {
articles: Article[];
total: number;
page: number;
totalPages: number;
hasMore: boolean;
}
function VideoCard({ article }: { article: Article }) {
const thumbSrc = article.coverImage
? article.coverImage.replace(".webp", "-thumb.webp")
: "/images/article-1.jpg";
return (
{article.title}
{format(new Date(article.publishedAt), "d. MMMM yyyy", { locale: de })}
);
}
function VideoCardSkeleton() {
return (
);
}
export default function VideosPage() {
usePageMeta("Volksmusik & Schlager Videos", "Volksmusik und Schlager Musikvideos, Live-Auftritte und Konzertmitschnitte bei FOLX TV. Die besten volkstümlichen Hits und Schlager-Stars im Video.");
const searchString = useSearch();
const [, setLocation] = useLocation();
const params = new URLSearchParams(searchString);
const currentPage = Math.max(1, parseInt(params.get("page") || "1"));
const limit = 12;
const { data, isLoading } = useQuery({
queryKey: [`/api/articles/category/Video?page=${currentPage}&limit=${limit}`],
});
useEffect(() => {
window.scrollTo({ top: 0, behavior: "smooth" });
}, [currentPage]);
const goToPage = (page: number) => {
if (page === 1) {
setLocation("/videos");
} else {
setLocation(`/videos?page=${page}`);
}
};
const totalPages = data?.totalPages || 1;
const articles = data?.articles || [];
const getPageNumbers = () => {
const pages: (number | "...")[] = [];
if (totalPages <= 7) {
for (let i = 1; i <= totalPages; i++) pages.push(i);
} else {
pages.push(1);
if (currentPage > 3) pages.push("...");
const start = Math.max(2, currentPage - 1);
const end = Math.min(totalPages - 1, currentPage + 1);
for (let i = start; i <= end; i++) pages.push(i);
if (currentPage < totalPages - 2) pages.push("...");
pages.push(totalPages);
}
return pages;
};
return (
Videos
{isLoading ? (
{Array.from({ length: 8 }).map((_, i) => (
))}
) : articles.length > 0 ? (
<>
{articles.flatMap((article, index) => {
const items: JSX.Element[] = [
,
];
if ((index + 1) % 3 === 0) {
items.push(
);
}
return items;
})}
{totalPages > 1 && (
)}
>
) : (
Noch keine Videos vorhanden.
)}
);
}