fix(navigation): replace div click handlers with semantic Next.js Link components
- Convert product cards in ArchivePage, IngredientWiki, and SearchResultsPage to Next.js <Link> - Support right-click / middle-click to open products in new tabs - Display native target URL preview in browser status bar on hover
This commit is contained in:
1 parent
1b914d25a5
commit
dc8a1bb079
3 files changed
+119
-106
No files matched your search
@@ -3,6 +3,7 @@ import React, { useState, useMemo, useEffect } from "react";
|
||||
import { Product, PetType } from "../lib/data/products";
|
||||
import { usePetStore } from "../lib/store/usePetStore";
|
||||
import { productService } from "../lib/services/productService";
|
||||
import Link from "next/link";
|
||||
import { motion, AnimatePresence } from "motion/react";
|
||||
import { ProductCardSkeleton } from "./Skeleton";
|
||||
import { toast } from "sonner";
|
||||
@@ -66,12 +67,14 @@ const CATEGORY_MAP: Record<string, { category?: string; query?: string; symptoms
|
||||
"شستشوی چشم": { category: "special-care", query: "چشم" },
|
||||
};
|
||||
|
||||
const ArchiveProductCard: React.FC<{ product: Product, onClick: (p: Product) => void }> = ({ product, onClick }) => {
|
||||
const ArchiveProductCard: React.FC<{ product: Product }> = ({ product }) => {
|
||||
const { addItem } = useCartStore();
|
||||
const [isAdding, setIsAdding] = useState(false);
|
||||
const activePet = usePetStore(state => state.pets.find(p => p.id === state.activePetId) || null);
|
||||
const productUrl = `/shop/${product.slug || product.id}`;
|
||||
|
||||
const handleAddToCart = (e: React.MouseEvent) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
setIsAdding(true);
|
||||
addItem(product, 1);
|
||||
@@ -97,75 +100,79 @@ const ArchiveProductCard: React.FC<{ product: Product, onClick: (p: Product) =>
|
||||
layout
|
||||
initial={{ opacity: 0, y: 20 }}
|
||||
animate={{ opacity: 1, y: 0 }}
|
||||
onClick={() => onClick(product)}
|
||||
className="group bg-white rounded-[2.5rem] border border-medical-gray-200 overflow-hidden hover:shadow-2xl transition-all cursor-pointer flex flex-col h-full relative"
|
||||
className="h-full"
|
||||
>
|
||||
{product.specialBadge && (
|
||||
<div className="absolute top-4 right-4 z-10 bg-canina-blue text-white text-[9px] font-black uppercase tracking-widest px-3 py-1 rounded-full shadow-lg">
|
||||
{product.specialBadge}
|
||||
</div>
|
||||
)}
|
||||
<Link
|
||||
href={productUrl}
|
||||
className="group bg-white rounded-[2.5rem] border border-medical-gray-200 overflow-hidden hover:shadow-2xl transition-all flex flex-col h-full relative"
|
||||
>
|
||||
{product.specialBadge && (
|
||||
<div className="absolute top-4 right-4 z-10 bg-canina-blue text-white text-[9px] font-black uppercase tracking-widest px-3 py-1 rounded-full shadow-lg">
|
||||
{product.specialBadge}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{compatibility && (
|
||||
<div className={`absolute top-14 right-4 z-10 text-[8px] font-black uppercase tracking-widest px-3 py-1 rounded-full shadow-md flex items-center gap-1 ${compatibility.type === 'alert' ? 'bg-amber-100 text-amber-700' :
|
||||
compatibility.type === 'success' ? 'bg-green-100 text-green-700' : 'bg-medical-gray-100 text-medical-gray-600'
|
||||
}`}>
|
||||
{compatibility.type === 'alert' ? <AlertCircle className="w-2.5 h-2.5" /> : compatibility.type === 'success' ? <Heart className="w-2.5 h-2.5" /> : <Sparkles className="w-2.5 h-2.5" />}
|
||||
{compatibility.text}
|
||||
</div>
|
||||
)}
|
||||
{compatibility && (
|
||||
<div className={`absolute top-14 right-4 z-10 text-[8px] font-black uppercase tracking-widest px-3 py-1 rounded-full shadow-md flex items-center gap-1 ${compatibility.type === 'alert' ? 'bg-amber-100 text-amber-700' :
|
||||
compatibility.type === 'success' ? 'bg-green-100 text-green-700' : 'bg-medical-gray-100 text-medical-gray-600'
|
||||
}`}>
|
||||
{compatibility.type === 'alert' ? <AlertCircle className="w-2.5 h-2.5" /> : compatibility.type === 'success' ? <Heart className="w-2.5 h-2.5" /> : <Sparkles className="w-2.5 h-2.5" />}
|
||||
{compatibility.text}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="aspect-square bg-medical-gray-50 flex items-center justify-center p-8 overflow-hidden relative">
|
||||
<SafeImage src={product.image} alt={product.name} className="w-full h-full group-hover:scale-110 transition-transform duration-700" imgClassName="object-contain" />
|
||||
<div className="absolute bottom-4 left-4 flex gap-2">
|
||||
{(product.suitableFor === "سگ" || product.suitableFor === "هر دو") && (
|
||||
<div className="w-7 h-7 bg-white rounded-lg flex items-center justify-center text-medical-gray-400 border border-medical-gray-100 shadow-sm">
|
||||
<Dog className="w-4 h-4" />
|
||||
</div>
|
||||
)}
|
||||
{(product.suitableFor === "گربه" || product.suitableFor === "هر دو") && (
|
||||
<div className="w-7 h-7 bg-white rounded-lg flex items-center justify-center text-medical-gray-400 border border-medical-gray-100 shadow-sm">
|
||||
<Cat className="w-4 h-4" />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="p-6 flex flex-col flex-1">
|
||||
<div className="text-[10px] font-bold text-canina-blue uppercase tracking-widest mb-2">{product.category}</div>
|
||||
<div className="flex flex-col gap-1 mb-3">
|
||||
<h3 dir="rtl" className="text-base font-black text-medical-gray-900 group-hover:text-canina-blue transition-colors leading-tight text-right font-vazir">
|
||||
{product.nameFa || product.name}
|
||||
</h3>
|
||||
{product.nameEn && (
|
||||
<span dir="ltr" className="text-[11px] font-bold text-slate-400 font-sans text-left block">
|
||||
{product.nameEn}
|
||||
</span>
|
||||
)}
|
||||
<div className="aspect-square bg-medical-gray-50 flex items-center justify-center p-8 overflow-hidden relative">
|
||||
<SafeImage src={product.image} alt={product.name} className="w-full h-full group-hover:scale-110 transition-transform duration-700" imgClassName="object-contain" />
|
||||
<div className="absolute bottom-4 left-4 flex gap-2">
|
||||
{(product.suitableFor === "سگ" || product.suitableFor === "هر دو") && (
|
||||
<div className="w-7 h-7 bg-white rounded-lg flex items-center justify-center text-medical-gray-400 border border-medical-gray-100 shadow-sm">
|
||||
<Dog className="w-4 h-4" />
|
||||
</div>
|
||||
)}
|
||||
{(product.suitableFor === "گربه" || product.suitableFor === "هر دو") && (
|
||||
<div className="w-7 h-7 bg-white rounded-lg flex items-center justify-center text-medical-gray-400 border border-medical-gray-100 shadow-sm">
|
||||
<Cat className="w-4 h-4" />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap gap-1">
|
||||
{product.symptoms.slice(0, 2).map((s, i) => (
|
||||
<span key={i} className="text-[9px] font-bold bg-medical-gray-100 text-medical-gray-500 px-2 py-0.5 rounded-md">
|
||||
{s}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
<div className="p-6 flex flex-col flex-1">
|
||||
<div className="text-[10px] font-bold text-canina-blue uppercase tracking-widest mb-2">{product.category}</div>
|
||||
<div className="flex flex-col gap-1 mb-3">
|
||||
<h3 dir="rtl" className="text-base font-black text-medical-gray-900 group-hover:text-canina-blue transition-colors leading-tight text-right font-vazir">
|
||||
{product.nameFa || product.name}
|
||||
</h3>
|
||||
{product.nameEn && (
|
||||
<span dir="ltr" className="text-[11px] font-bold text-slate-400 font-sans text-left block">
|
||||
{product.nameEn}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="mt-auto flex items-center justify-between pt-4 border-t border-medical-gray-50">
|
||||
<span className="font-black text-medical-gray-900 font-vazir">{product.price}</span>
|
||||
<button
|
||||
onClick={handleAddToCart}
|
||||
disabled={isAdding}
|
||||
className="w-10 h-10 rounded-xl bg-medical-gray-50 text-canina-blue flex items-center justify-center group-hover:bg-canina-blue group-hover:text-white transition-all disabled:opacity-50"
|
||||
>
|
||||
{isAdding ? <Loader2 className="w-4 h-4 animate-spin" /> : <Plus className="w-4 h-4" />}
|
||||
</button>
|
||||
<div className="flex flex-wrap gap-1">
|
||||
{product.symptoms.slice(0, 2).map((s, i) => (
|
||||
<span key={i} className="text-[9px] font-bold bg-medical-gray-100 text-medical-gray-500 px-2 py-0.5 rounded-md">
|
||||
{s}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="mt-auto flex items-center justify-between pt-4 border-t border-medical-gray-50">
|
||||
<span className="font-black text-medical-gray-900 font-vazir">{product.price}</span>
|
||||
<button
|
||||
onClick={handleAddToCart}
|
||||
disabled={isAdding}
|
||||
className="w-10 h-10 rounded-xl bg-medical-gray-50 text-canina-blue flex items-center justify-center group-hover:bg-canina-blue group-hover:text-white transition-all disabled:opacity-50"
|
||||
>
|
||||
{isAdding ? <Loader2 className="w-4 h-4 animate-spin" /> : <Plus className="w-4 h-4" />}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Link>
|
||||
</motion.div>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
import { useRouter } from 'next/navigation';
|
||||
|
||||
@@ -491,7 +498,7 @@ export default function ArchivePage({
|
||||
<div key="grid" className="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-4 gap-6">
|
||||
<AnimatePresence mode="popLayout">
|
||||
{filteredProducts.map((p: Product) => (
|
||||
<ArchiveProductCard key={p.id} product={p} onClick={(p) => router.push(`/shop/${p.slug || p.id}`)} />
|
||||
<ArchiveProductCard key={p.id} product={p} />
|
||||
))}
|
||||
</AnimatePresence>
|
||||
</div>
|
||||
|
||||
@@ -6,6 +6,7 @@ import { FlaskConical, CheckCircle2, ChevronRight, ChevronLeft, Beaker, Search }
|
||||
import { useSettingsStore } from "../lib/store/settingsStore";
|
||||
import { productService } from "../lib/services/productService";
|
||||
|
||||
import Link from "next/link";
|
||||
import { SCIENTIFIC_TERMS } from "../lib/data/scientificTerms";
|
||||
import { useRouter, useSearchParams } from 'next/navigation';
|
||||
|
||||
@@ -236,14 +237,14 @@ export default function IngredientWiki() {
|
||||
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-6 relative z-10">
|
||||
{hasIngredient.length > 0 ? hasIngredient.map(p => (
|
||||
<div
|
||||
<Link
|
||||
key={p.id}
|
||||
onClick={() => router.push(`/shop/${p.slug || p.id}`)}
|
||||
className="bg-white rounded-[2.5rem] p-6 shadow-xl hover:scale-105 transition-transform cursor-pointer group"
|
||||
href={`/shop/${p.slug || p.id}`}
|
||||
className="bg-white rounded-[2.5rem] p-6 shadow-xl hover:scale-105 transition-transform cursor-pointer group block"
|
||||
>
|
||||
<img src={p.image} alt={p.name} className="w-24 h-24 object-contain mx-auto mb-4" referrerPolicy="no-referrer" />
|
||||
<h4 className="text-sm font-black text-center text-medical-gray-900 group-hover:text-canina-blue transition-colors px-2">{p.name}</h4>
|
||||
</div>
|
||||
</Link>
|
||||
)) : (
|
||||
<div className="col-span-full py-8 text-center">
|
||||
<p className="text-medical-gray-400 font-bold italic mb-3">محصولی با این ماده مؤثره یافت نشد.</p>
|
||||
|
||||
@@ -6,6 +6,7 @@ import { motion } from "motion/react";
|
||||
import { Product } from "../lib/data/products";
|
||||
import { productService } from "../lib/services/productService";
|
||||
|
||||
import Link from "next/link";
|
||||
import { useRouter } from 'next/navigation';
|
||||
|
||||
export default function SearchResultsPage({ query }: { query: string }) {
|
||||
@@ -64,46 +65,50 @@ export default function SearchResultsPage({ query }: { query: string }) {
|
||||
<motion.div
|
||||
key={product.id}
|
||||
layoutId={product.id}
|
||||
onClick={() => router.push(`/shop/${product.slug || product.id}`)}
|
||||
className="bg-white rounded-[2.5rem] p-8 border border-medical-gray-200 group cursor-pointer hover:shadow-2xl hover:shadow-canina-blue/10 transition-all flex flex-col relative"
|
||||
className="h-full"
|
||||
>
|
||||
<div className="relative aspect-square mb-8 bg-medical-gray-50 rounded-[2rem] overflow-hidden p-6 flex items-center justify-center">
|
||||
<img
|
||||
src={product.image}
|
||||
alt={product.nameFa || product.name}
|
||||
className="w-full h-full object-contain group-hover:scale-110 transition-transform duration-500"
|
||||
referrerPolicy="no-referrer"
|
||||
/>
|
||||
{product.specialBadge && (
|
||||
<div className="absolute top-4 right-4 bg-medical-gray-900 text-white text-[8px] font-black px-3 py-1 rounded-full uppercase tracking-widest">
|
||||
{product.specialBadge}
|
||||
</div>
|
||||
)}
|
||||
{compatibility && (
|
||||
<div className={`absolute top-14 right-4 z-10 text-[8px] font-black uppercase tracking-widest px-3 py-1 rounded-full shadow-md flex items-center gap-1 ${
|
||||
compatibility.type === 'alert' ? 'bg-amber-100 text-amber-700' :
|
||||
compatibility.type === 'success' ? 'bg-green-100 text-green-700' : 'bg-medical-gray-100 text-medical-gray-600'
|
||||
}`}>
|
||||
{compatibility.type === 'alert' ? <AlertCircle className="w-2.5 h-2.5" /> : compatibility.type === 'success' ? <Heart className="w-2.5 h-2.5" /> : <Sparkles className="w-2.5 h-2.5" />}
|
||||
{compatibility.text}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="flex-1">
|
||||
<span className="text-[10px] font-black text-canina-blue uppercase tracking-widest mb-2 block">{product.category}</span>
|
||||
<h3 className="text-xl font-black text-medical-gray-900 mb-2 leading-tight group-hover:text-canina-blue transition-colors">{product.nameFa || product.name}</h3>
|
||||
<p className="text-xs text-medical-gray-400 line-clamp-2 leading-relaxed mb-6">{product.benefits}</p>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center justify-between pt-6 border-t border-medical-gray-100 italic">
|
||||
<div>
|
||||
<span className="text-lg font-black text-medical-gray-900">{product.price}</span>
|
||||
<Link
|
||||
href={`/shop/${product.slug || product.id}`}
|
||||
className="bg-white rounded-[2.5rem] p-8 border border-medical-gray-200 group hover:shadow-2xl hover:shadow-canina-blue/10 transition-all flex flex-col relative h-full block"
|
||||
>
|
||||
<div className="relative aspect-square mb-8 bg-medical-gray-50 rounded-[2rem] overflow-hidden p-6 flex items-center justify-center">
|
||||
<img
|
||||
src={product.image}
|
||||
alt={product.nameFa || product.name}
|
||||
className="w-full h-full object-contain group-hover:scale-110 transition-transform duration-500"
|
||||
referrerPolicy="no-referrer"
|
||||
/>
|
||||
{product.specialBadge && (
|
||||
<div className="absolute top-4 right-4 bg-medical-gray-900 text-white text-[8px] font-black px-3 py-1 rounded-full uppercase tracking-widest">
|
||||
{product.specialBadge}
|
||||
</div>
|
||||
)}
|
||||
{compatibility && (
|
||||
<div className={`absolute top-14 right-4 z-10 text-[8px] font-black uppercase tracking-widest px-3 py-1 rounded-full shadow-md flex items-center gap-1 ${
|
||||
compatibility.type === 'alert' ? 'bg-amber-100 text-amber-700' :
|
||||
compatibility.type === 'success' ? 'bg-green-100 text-green-700' : 'bg-medical-gray-100 text-medical-gray-600'
|
||||
}`}>
|
||||
{compatibility.type === 'alert' ? <AlertCircle className="w-2.5 h-2.5" /> : compatibility.type === 'success' ? <Heart className="w-2.5 h-2.5" /> : <Sparkles className="w-2.5 h-2.5" />}
|
||||
{compatibility.text}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<button className="bg-medical-gray-900 text-white w-10 h-10 rounded-xl flex items-center justify-center group-hover:bg-canina-blue transition-colors">
|
||||
<ChevronLeft className="w-5 h-5" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="flex-1">
|
||||
<span className="text-[10px] font-black text-canina-blue uppercase tracking-widest mb-2 block">{product.category}</span>
|
||||
<h3 className="text-xl font-black text-medical-gray-900 mb-2 leading-tight group-hover:text-canina-blue transition-colors">{product.nameFa || product.name}</h3>
|
||||
<p className="text-xs text-medical-gray-400 line-clamp-2 leading-relaxed mb-6">{product.benefits}</p>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center justify-between pt-6 border-t border-medical-gray-100 italic">
|
||||
<div>
|
||||
<span className="text-lg font-black text-medical-gray-900">{product.price}</span>
|
||||
</div>
|
||||
<div className="bg-medical-gray-900 text-white w-10 h-10 rounded-xl flex items-center justify-center group-hover:bg-canina-blue transition-colors">
|
||||
<ChevronLeft className="w-5 h-5" />
|
||||
</div>
|
||||
</div>
|
||||
</Link>
|
||||
</motion.div>
|
||||
)
|
||||
})}
|
||||
@@ -124,12 +129,12 @@ export default function SearchResultsPage({ query }: { query: string }) {
|
||||
<h3 className="text-2xl font-black text-medical-gray-900 mb-10 italic">محصولات پیشنهادی (پرفروش)</h3>
|
||||
<div className="grid md:grid-cols-3 gap-8 opacity-60 hover:opacity-100 transition-opacity">
|
||||
{bestSellers.map(p => (
|
||||
<div key={p.id} onClick={() => router.push(`/shop/${p.id}`)} className="cursor-pointer group">
|
||||
<Link key={p.id} href={`/shop/${p.slug || p.id}`} className="cursor-pointer group block">
|
||||
<div className="aspect-square bg-white rounded-[2rem] p-6 mb-4 border border-medical-gray-100 flex items-center justify-center">
|
||||
<img src={p.image} className="w-40 h-40 object-contain group-hover:scale-105 transition-transform" />
|
||||
</div>
|
||||
<h4 className="font-black text-medical-gray-900 text-center">{p.name}</h4>
|
||||
</div>
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user