fix: restore wiki to dictionary, create dynamic blog pages and backend wiki CRUD
This commit is contained in:
1 parent
945c007a79
commit
dcfc4acae4
13 files changed
+328
-119
No files matched your search
@@ -5,48 +5,22 @@ import { ChevronRight, Calendar, User, ArrowLeft, Sparkles, BookOpen } from "luc
|
||||
import { Product } from "../lib/data/products";
|
||||
import { productService } from "../lib/services/productService";
|
||||
|
||||
const BLOG_POSTS = [
|
||||
{
|
||||
id: "p1",
|
||||
title: "مزایای شگفتانگیز صدف لبسبز نیوزیلند برای مفاصل پت",
|
||||
excerpt: "صدف لبسبز (Perna Canaliculus) تنها منبع طبیعی حاوی گلیکوزآمینگلیکانها (GAG) در غلظت بسیار بالا محسوب میشود.",
|
||||
image: "https://images.unsplash.com/photo-1599443015574-be5fe8a05783?auto=format&fit=crop&q=80&w=800",
|
||||
date: "۲۵ اردیبهشت ۱۴۰۳",
|
||||
author: "دکتر کلاوس هنینگ",
|
||||
content: `
|
||||
صدف لبسبز نیوزیلندی قلب تپنده محصولات ارتوپدی کانینا است. این صدف که منحصراً در آبهای فوقالعاده تمیز نیوزیلند تکثیر میشود، حاوی ترکیبات ضدالتهابی طبیعی است که در هیچ منبع دیگری به این غلظت یافت نمیشود.
|
||||
|
||||
چرا برای سگهای نژاد بزرگ حیاتی است؟
|
||||
در سگهای نژاد بزرگ، سرعت رشد اسکلتی بسیار بالاست. اگر مفاصل و تاندونها با این سرعت هماهنگ نشوند، بدشکلیهای ماندگار ایجاد میشود. GAG موجود در صدف، مانند چسب بیولوژیک عمل کرده و بافت غضروفی را ترمیم میکند.
|
||||
|
||||
مکمل Canhydrox GAG با دارا بودن ۱۵٪ پودر صدف لبسبز خالص، استاندارد طلایی در دامپزشکی آلمان است.
|
||||
`
|
||||
},
|
||||
{
|
||||
id: "p2",
|
||||
title: "چگونه سیستم ایمنی پت خود را در برابر بیماریهای فصلی تقویت کنیم؟",
|
||||
excerpt: "آغوز (Colostrum) اولین سد دفاعی طبیعت است. با ایمیونبوستر کانینا، پت شما در برابر ویروسها بیمه میشود.",
|
||||
image: "https://images.unsplash.com/photo-1576091160550-217359f42f8c?auto=format&fit=crop&q=80&w=800",
|
||||
date: "۲۰ اردیبهشت ۱۴۰۳",
|
||||
author: "دکتر النا اشمیت",
|
||||
content: "ایمنی بدن یک مکانیزم پیچیده است. استفاده از Immun-Booster به ویژه در دوران واکسیناسیون یا جابجایی، به بدن پت کمک میکند تا آنتیبادیهای لازم را با سرعت بیشتری تولید کند."
|
||||
},
|
||||
{
|
||||
id: "p3",
|
||||
title: "اهمیت اسیدهای چرب امگا ۳ در درخشش پوشش مویی",
|
||||
excerpt: "ریزش موی شدید در سگ و گربه معمولاً نشانه کمبود اسیدهای چرب ضروری EPA و DHA است. روغن سالمون پرس سرد راه حل نهایی است.",
|
||||
image: "https://images.unsplash.com/photo-1516734212186-a967f81ad0d7?auto=format&fit=crop&q=80&w=800",
|
||||
date: "۱۵ اردیبهشت ۱۴۰۳",
|
||||
author: "دکتر ماری کونیگ",
|
||||
content: "روغن سالمون کانینا به روش پرس سرد تهیه شده تا تمامی ویتامینهای حساس به حرارت حفظ شوند. این روغن نه تنها پوست را مرطوب نگه میدارد، بلکه التهابات مفصلی را نیز کاهش میدهد."
|
||||
}
|
||||
];
|
||||
export interface BlogPost {
|
||||
id: string;
|
||||
slug: string;
|
||||
title: string;
|
||||
excerpt: string;
|
||||
image: string;
|
||||
date: string;
|
||||
author: string;
|
||||
content: string;
|
||||
}
|
||||
|
||||
import { useRouter } from 'next/navigation';
|
||||
|
||||
export default function BlogPage() {
|
||||
export default function BlogPage({ blogs = [] }: { blogs: BlogPost[] }) {
|
||||
const router = useRouter();
|
||||
const [selectedPost, setSelectedPost] = React.useState<typeof BLOG_POSTS[0] | null>(null);
|
||||
const [selectedPost, setSelectedPost] = React.useState<BlogPost | null>(null);
|
||||
const [products, setProducts] = React.useState<Product[]>([]);
|
||||
|
||||
React.useEffect(() => {
|
||||
@@ -144,10 +118,10 @@ export default function BlogPage() {
|
||||
<div className="bg-white rounded-[3rem] border border-medical-gray-200 p-10 shadow-xl">
|
||||
<h4 className="text-xl font-black italic mb-6">محبوبترین مقالات</h4>
|
||||
<div className="space-y-6">
|
||||
{BLOG_POSTS.map(p => (
|
||||
{blogs.map(p => (
|
||||
<div
|
||||
key={p.id}
|
||||
onClick={() => setSelectedPost(p)}
|
||||
onClick={() => router.push(`/blog/${p.slug}`)}
|
||||
className="flex items-center gap-4 cursor-pointer group"
|
||||
>
|
||||
<div className="w-16 h-16 rounded-2xl overflow-hidden shrink-0">
|
||||
@@ -194,17 +168,18 @@ export default function BlogPage() {
|
||||
</div>
|
||||
|
||||
{/* Featured Post */}
|
||||
{blogs.length > 0 && (
|
||||
<div className="mb-20">
|
||||
<motion.div
|
||||
initial={{ opacity: 0, y: 20 }}
|
||||
animate={{ opacity: 1, y: 0 }}
|
||||
className="bg-white rounded-[3.5rem] overflow-hidden border border-medical-gray-200 shadow-2xl flex flex-col lg:flex-row cursor-pointer group"
|
||||
onClick={() => setSelectedPost(BLOG_POSTS[0])}
|
||||
onClick={() => router.push(`/blog/${blogs[0].slug}`)}
|
||||
>
|
||||
<div className="lg:w-1/2 aspect-video lg:aspect-auto">
|
||||
<img
|
||||
src={BLOG_POSTS[0].image}
|
||||
alt={BLOG_POSTS[0].title}
|
||||
src={blogs[0].image}
|
||||
alt={blogs[0].title}
|
||||
className="w-full h-full object-cover group-hover:scale-105 transition-transform duration-700"
|
||||
/>
|
||||
</div>
|
||||
@@ -213,14 +188,14 @@ export default function BlogPage() {
|
||||
<div className="bg-canina-blue/10 px-3 py-1 rounded-full uppercase tracking-widest">تخصصی</div>
|
||||
<div className="flex items-center gap-1">
|
||||
<Calendar className="w-3 h-3" />
|
||||
{BLOG_POSTS[0].date}
|
||||
{blogs[0].date}
|
||||
</div>
|
||||
</div>
|
||||
<h2 className="text-3xl lg:text-4xl font-black text-medical-gray-900 mb-6 leading-tight group-hover:text-canina-blue transition-colors">
|
||||
{BLOG_POSTS[0].title}
|
||||
{blogs[0].title}
|
||||
</h2>
|
||||
<p className="text-lg text-medical-gray-500 mb-8 leading-relaxed italic">
|
||||
{BLOG_POSTS[0].excerpt}
|
||||
{blogs[0].excerpt}
|
||||
</p>
|
||||
<div className="flex items-center justify-between pt-8 border-t border-medical-gray-100">
|
||||
<div className="flex items-center gap-3">
|
||||
@@ -228,8 +203,8 @@ export default function BlogPage() {
|
||||
<User className="w-6 h-6" />
|
||||
</div>
|
||||
<div className="text-sm">
|
||||
<div className="font-black text-medical-gray-900">{BLOG_POSTS[0].author}</div>
|
||||
<div className="font-bold text-medical-gray-400">محقق ارشد کانینا</div>
|
||||
<div className="font-black text-medical-gray-900">{blogs[0].author}</div>
|
||||
<div className="font-bold text-medical-gray-400">نویسنده کانینا</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-2 text-canina-blue font-black">
|
||||
@@ -240,10 +215,11 @@ export default function BlogPage() {
|
||||
</div>
|
||||
</motion.div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Post Grid */}
|
||||
<div className="grid md:grid-cols-2 gap-8">
|
||||
{BLOG_POSTS.slice(1).map((post, idx) => (
|
||||
{blogs.slice(1).map((post, idx) => (
|
||||
<motion.div
|
||||
key={post.id}
|
||||
initial={{ opacity: 0, y: 20 }}
|
||||
@@ -251,7 +227,7 @@ export default function BlogPage() {
|
||||
viewport={{ once: true }}
|
||||
transition={{ delay: idx * 0.1 }}
|
||||
className="bg-white rounded-[3rem] overflow-hidden border border-medical-gray-200 shadow-xl group hover:shadow-2xl transition-all cursor-pointer"
|
||||
onClick={() => setSelectedPost(post)}
|
||||
onClick={() => router.push(`/blog/${post.slug}`)}
|
||||
>
|
||||
<div className="aspect-[16/9] overflow-hidden">
|
||||
<img
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
import { useMemo, useState, useEffect } from "react";
|
||||
import { INGREDIENTS_WIKI, Product } from "../lib/data/products";
|
||||
import { Product, IngredientInfo } from "../lib/data/products";
|
||||
import { motion } from "motion/react";
|
||||
import { FlaskConical, CheckCircle2, ChevronRight, ChevronLeft, Beaker } from "lucide-react";
|
||||
import { useSettingsStore } from "../lib/store/settingsStore";
|
||||
@@ -11,24 +11,26 @@ import { useRouter } from 'next/navigation';
|
||||
export default function IngredientWiki() {
|
||||
const router = useRouter();
|
||||
const texts = useSettingsStore(state => state.texts);
|
||||
const [ingredientsWiki, setIngredientsWiki] = useState<IngredientInfo[]>([]);
|
||||
const [products, setProducts] = useState<Product[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
productService.getProducts().then(data => setProducts(data));
|
||||
|
||||
fetch('http://localhost:4000/api/wiki')
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
const mapped = data.map((item: any) => ({
|
||||
id: item.key,
|
||||
name: item.term,
|
||||
description: item.definition,
|
||||
benefits: item.keywords ? JSON.parse(item.keywords) : []
|
||||
}));
|
||||
setIngredientsWiki(mapped);
|
||||
})
|
||||
.catch(err => console.error("Failed to fetch wiki:", err));
|
||||
}, []);
|
||||
|
||||
const ingredientsWiki = useMemo(() => {
|
||||
const jsonStr = texts['ingredients_wiki'];
|
||||
if (jsonStr) {
|
||||
try {
|
||||
return JSON.parse(jsonStr) as typeof INGREDIENTS_WIKI;
|
||||
} catch (e) {
|
||||
console.error("Failed to parse ingredients_wiki from DB setting:", e);
|
||||
}
|
||||
}
|
||||
return INGREDIENTS_WIKI;
|
||||
}, [texts]);
|
||||
|
||||
return (
|
||||
<div className="bg-white py-12 px-4 overflow-hidden font-vazir" dir="rtl">
|
||||
<div className="max-w-7xl mx-auto">
|
||||
|
||||
Reference in new issue
Block a user