feat: complete app democking, fix types, add blogs api

This commit is contained in:
parsa committed 2026-06-12 22:53:57 +03:30
1 parent 6027e635db
commit 945c007a79
25 files changed
+557 -56

No files matched your search

+20 -5
View File
@@ -4,14 +4,29 @@ import FeaturedProducts from "../components/FeaturedProducts";
import VetGallery from "../components/VetGallery";
import Link from 'next/link';
export default function Home() {
async function getHomeData() {
try {
const res = await fetch('http://localhost:4000/api/home', { next: { revalidate: 60 } });
if (!res.ok) throw new Error('Failed to fetch home data');
return res.json();
} catch (error) {
console.error('Home data fetch error:', error);
return null;
}
}
export default async function Home() {
const data = await getHomeData();
const banners = data?.heroBanners || [];
const testimonials = data?.vetTestimonials || [];
const rules = data?.smartAdvisorRules || [];
return (
<>
<Hero />
{/* SmartAdvisor uses uiStore/userStore internally and handles routing automatically */}
<SmartAdvisor />
<Hero banners={banners} />
<SmartAdvisor rules={rules} />
<FeaturedProducts />
<VetGallery />
<VetGallery testimonials={testimonials} />
{/* Navigation to Sections */}
<section className="py-20 bg-medical-gray-50 border-y border-medical-gray-100">
@@ -0,0 +1,76 @@
import Link from 'next/link';
import { ChevronRight } from 'lucide-react';
import type { Metadata } from 'next';
async function getBlog(slug: string) {
try {
const res = await fetch(`http://localhost:4000/api/blogs/${slug}`, { next: { revalidate: 60 } });
if (!res.ok) throw new Error('Failed to fetch blog');
return res.json();
} catch (error) {
console.error(error);
return null;
}
}
export async function generateMetadata({ params }: { params: { slug: string } }): Promise<Metadata> {
const blog = await getBlog(params.slug);
if (!blog) return { title: 'مقاله یافت نشد' };
return {
title: blog.metaTitle || blog.title,
description: blog.metaDescription || blog.title,
};
}
export default async function BlogPage({ params }: { params: { slug: string } }) {
const blog = await getBlog(params.slug);
if (!blog) {
return (
<div className="min-h-[50vh] flex flex-col items-center justify-center font-vazir text-center" dir="rtl">
<h1 className="text-3xl font-black text-medical-gray-900 mb-4">مقاله‌ای یافت نشد</h1>
<Link href="/wiki" className="text-canina-blue font-bold flex items-center gap-2">
<ChevronRight className="w-4 h-4" />
بازگشت به دانشنامه
</Link>
</div>
);
}
return (
<div className="bg-white py-20 px-4 font-vazir" dir="rtl">
<div className="max-w-4xl mx-auto">
<Link href="/wiki" className="inline-flex items-center gap-2 text-medical-gray-400 hover:text-canina-blue transition-colors font-bold mb-8">
<ChevronRight className="w-5 h-5" />
بازگشت به مقالات
</Link>
{blog.imageUrl && (
<div className="aspect-video rounded-[2rem] overflow-hidden mb-12 shadow-xl border border-medical-gray-100">
<img src={blog.imageUrl} alt={blog.title} className="w-full h-full object-cover" />
</div>
)}
<h1 className="text-4xl lg:text-5xl font-black text-medical-gray-900 mb-6 leading-tight">
{blog.title}
</h1>
<div className="flex items-center gap-4 text-sm font-bold text-medical-gray-400 mb-12 pb-8 border-b border-medical-gray-100">
<span>نوشته شده در {new Date(blog.createdAt).toLocaleDateString('fa-IR')}</span>
{blog.author && (
<>
<span className="w-1 h-1 rounded-full bg-medical-gray-300" />
<span>توسط {blog.author.firstName} {blog.author.lastName}</span>
</>
)}
</div>
<div
className="prose prose-lg prose-medical-gray max-w-none prose-headings:font-black prose-p:leading-relaxed prose-a:text-canina-blue"
dangerouslySetInnerHTML={{ __html: blog.content }}
/>
</div>
</div>
);
}
+54 -5
View File
@@ -1,11 +1,60 @@
import IngredientWiki from "../../components/IngredientWiki";
import Link from 'next/link';
import type { Metadata } from 'next';
export const metadata: Metadata = {
title: 'دانشنامه ترکیبات دارویی',
description: 'اطلاعات کامل در مورد مواد موثره، ویتامین‌ها و ترکیبات گیاهی به کار رفته در محصولات تخصصی کانینا ایران.',
title: 'دانشنامه و مقالات علمی',
description: 'مقالات تخصصی و آموزشی درباره تغذیه و سلامت حیوانات خانگی',
};
export default function WikiPage() {
return <IngredientWiki />;
async function getBlogs() {
try {
const res = await fetch('http://localhost:4000/api/blogs', { next: { revalidate: 60 } });
if (!res.ok) throw new Error('Failed to fetch blogs');
return res.json();
} catch (error) {
console.error(error);
return [];
}
}
export default async function WikiPage() {
const blogs = await getBlogs();
return (
<div className="bg-white py-20 px-4 font-vazir" dir="rtl">
<div className="max-w-7xl mx-auto">
<h1 className="text-4xl font-black text-medical-gray-900 mb-12 text-center">دانشنامه و مقالات علمی</h1>
<div className="grid md:grid-cols-2 lg:grid-cols-3 gap-8">
{blogs.map((blog: any) => (
<Link key={blog.id} href={`/wiki/${blog.slug}`} className="group block">
<div className="bg-medical-gray-50 rounded-[2rem] overflow-hidden border border-medical-gray-100 hover:shadow-2xl transition-all duration-300 h-full flex flex-col">
{blog.imageUrl && (
<div className="aspect-video overflow-hidden">
<img src={blog.imageUrl} alt={blog.title} className="w-full h-full object-cover group-hover:scale-105 transition-transform duration-500" />
</div>
)}
<div className="p-6 flex-1 flex flex-col">
<h3 className="text-xl font-black text-medical-gray-900 mb-4 group-hover:text-canina-blue transition-colors">
{blog.title}
</h3>
<div className="text-sm text-medical-gray-500 line-clamp-3 mb-6" dangerouslySetInnerHTML={{ __html: blog.content.substring(0, 150) + '...' }} />
<div className="mt-auto flex items-center justify-between text-xs font-bold text-medical-gray-400">
<span>{new Date(blog.createdAt).toLocaleDateString('fa-IR')}</span>
<span className="text-canina-blue">مطالعه مقاله &larr;</span>
</div>
</div>
</div>
</Link>
))}
{blogs.length === 0 && (
<div className="col-span-full py-20 text-center text-medical-gray-400 font-bold">
مقاله‌ای یافت نشد.
</div>
)}
</div>
</div>
</div>
);
}