"use client"; import React, { useState } from 'react'; import Link from 'next/link'; import Image from 'next/image'; import { Post } from '@/types/types'; import { cn } from '@/lib/utils'; import { Calendar, ArrowRight } from 'lucide-react'; interface PostsGridProps { posts: Post[]; } const POSTS_PER_PAGE = 6; const categories = [ { id: 'wszystkie', label: 'Wszystkie' }, { id: 'klimatyzacja', label: 'Klimatyzacja' }, { id: 'pompy-ciepla', label: 'Pompy ciepła' }, { id: 'porady', label: 'Porady' }, ]; export function PostsGrid({ posts }: PostsGridProps) { const [activeCategory, setActiveCategory] = useState('wszystkie'); const [visibleCount, setVisibleCount] = useState(POSTS_PER_PAGE); const filteredPosts = posts.filter( (post) => activeCategory === 'wszystkie' || post.category === activeCategory ); const visiblePosts = filteredPosts.slice(0, visibleCount); const hasMore = visibleCount < filteredPosts.length; const handleShowMore = () => { setVisibleCount(prev => prev + POSTS_PER_PAGE); }; const handleCategoryChange = (categoryId: string) => { setActiveCategory(categoryId); setVisibleCount(POSTS_PER_PAGE); // Reset paginacji przy zmianie kategorii }; const categoryLabels: Record = { 'klimatyzacja': 'Klimatyzacja', 'pompy-ciepla': 'Pompy Ciepła', 'porady': 'Porady' }; return (
{/* Filtry */}
{categories.map((category) => ( ))}
{/* Siatka Artykułów */}
{visiblePosts.map((post) => { const dateObj = new Date(post.date); const formattedDate = dateObj.toLocaleDateString('pl-PL', { day: 'numeric', month: 'long', year: 'numeric' }); return (
{post.title}
{categoryLabels[post.category] || post.category}
{formattedDate}

{post.title}

{post.excerpt}

Czytaj więcej
); })}
{visiblePosts.length === 0 && (

Brak artykułów w tej kategorii.

)} {/* Pokaż więcej */} {hasMore && (
)}
); }