"use client"; import { useState, useEffect } from "react"; import Link from "next/link"; import { Card, CardHeader, CardTitle, CardContent, CardFooter, } from "@/components/ui/card"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { ArrowRight, Loader2 } from "lucide-react"; import { pb, getPbImage, type PBPost } from "@/lib/pb"; // Импортируем тип отсюда import { Dictionary } from "@/lib/IDict"; interface BlogPreviewProps { lang: string; dict: Dictionary["blog"]; } export function BlogPreview({ lang, dict }: BlogPreviewProps) { const [posts, setPosts] = useState([]); const [loading, setLoading] = useState(true); useEffect(() => { if (!lang) return; async function fetchPosts() { try { setLoading(true); // Тянем из нужной языковой коллекции (posts_ru или posts_en) const result = await pb .collection(`posts_${lang}`) .getList(1, 3, { filter: "published = true", sort: "-created", requestKey: null, }); setPosts(result.items); } catch (error) { console.error("Ошибка загрузки логов:", error); } finally { setLoading(false); } } fetchPosts(); }, [lang]); if (loading) { return (
); } // Если записей нет, показываем либо ничего, либо сообщение об ошибке из словаря if (posts.length === 0) return null; return (
{dict.badge}

{dict.title}

{posts.map((post) => ( {post.image && (
{post.title}
)}
{new Date(post.created).toLocaleDateString( lang === "ru" ? "ru-RU" : "en-US", )}
{post.title}

{post.excerpt}

))}
); }