/
masterOK
/
FEF
Обзор
Документация
Войти
/
masterOK
/
FEF
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
BlogPage.tsx
98 строк
3 KB
masterOK
upload files
10 ноя 2025, 19:52
10 ноя 2025, 19:52
2cb4a49
Код
Авторство
О чём код?
import { useQuery } from "@tanstack/react-query"; import { Link } from "wouter"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Badge } from "@/components/ui/badge"; import { Skeleton } from "@/components/ui/skeleton"; import { Calendar, User } from "lucide-react"; interface BlogPost { id: string; title: string; slug: string; excerpt: string | null; category: string | null; publishedAt: string | null; author: { fullName: string; }; } export default function BlogPage() { const { data: posts, isLoading } = useQuery<BlogPost[]>({ queryKey: ["/api/blog"], }); if (isLoading) { return ( <div className="container mx-auto px-4 py-12"> <Skeleton className="h-12 w-64 mb-8" /> <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6"> {[...Array(6)].map((_, i) => ( <Skeleton key={i} className="h-64" /> ))} </div> </div> ); } return ( <div className="min-h-screen bg-muted/30"> <div className="bg-gradient-to-r from-primary/20 to-primary/10 py-16"> <div className="container mx-auto px-4"> <h1 className="text-4xl font-bold mb-4">Блог USLUGI.ru</h1> <p className="text-lg text-muted-foreground"> Полезные статьи о ремонте, обслуживании и сервисе </p> </div> </div> <div className="container mx-auto px-4 py-12"> {!posts || posts.length === 0 ? ( <Card> <CardContent className="p-12 text-center text-muted-foreground"> Статьи пока не опубликованы </CardContent> </Card> ) : ( <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6"> {posts.map((post) => ( <Link key={post.id} href={`/blog/${post.slug}`}> <span> <Card className="h-full hover-elevate active-elevate-2" data-testid={`card-blog-${post.slug}`}> <CardHeader> {post.category && ( <Badge variant="secondary" className="w-fit mb-2"> {post.category} </Badge> )} <CardTitle className="line-clamp-2">{post.title}</CardTitle> </CardHeader> <CardContent> {post.excerpt && ( <p className="text-sm text-muted-foreground line-clamp-3 mb-4"> {post.excerpt} </p> )} <div className="flex items-center gap-4 text-xs text-muted-foreground"> <div className="flex items-center gap-1"> <User className="h-3 w-3" /> {post.author.fullName} </div> {post.publishedAt && ( <div className="flex items-center gap-1"> <Calendar className="h-3 w-3" /> {new Date(post.publishedAt).toLocaleDateString('ru-RU')} </div> )} </div> </CardContent> </Card> </span> </Link> ))} </div> )} </div> </div> ); }