From dc8a1bb0793de3e2725ae7e107468e60b328ad5a Mon Sep 17 00:00:00 2001 From: parsa aghaei Date: Tue, 21 Jul 2026 12:27:58 +0330 Subject: [PATCH] fix(navigation): replace div click handlers with semantic Next.js Link components - Convert product cards in ArchivePage, IngredientWiki, and SearchResultsPage to Next.js - Support right-click / middle-click to open products in new tabs - Display native target URL preview in browser status bar on hover --- .../application/components/ArchivePage.tsx | 131 +++++++++--------- .../application/components/IngredientWiki.tsx | 9 +- .../components/SearchResultsPage.tsx | 85 ++++++------ 3 files changed, 119 insertions(+), 106 deletions(-) diff --git a/frontend/application/components/ArchivePage.tsx b/frontend/application/components/ArchivePage.tsx index 35841d55..d3cce503 100644 --- a/frontend/application/components/ArchivePage.tsx +++ b/frontend/application/components/ArchivePage.tsx @@ -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 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 && ( -
- {product.specialBadge} -
- )} + + {product.specialBadge && ( +
+ {product.specialBadge} +
+ )} - {compatibility && ( -
- {compatibility.type === 'alert' ? : compatibility.type === 'success' ? : } - {compatibility.text} -
- )} + {compatibility && ( +
+ {compatibility.type === 'alert' ? : compatibility.type === 'success' ? : } + {compatibility.text} +
+ )} -
- -
- {(product.suitableFor === "سگ" || product.suitableFor === "هر دو") && ( -
- -
- )} - {(product.suitableFor === "گربه" || product.suitableFor === "هر دو") && ( -
- -
- )} -
-
- -
-
{product.category}
-
-

- {product.nameFa || product.name} -

- {product.nameEn && ( - - {product.nameEn} - - )} +
+ +
+ {(product.suitableFor === "سگ" || product.suitableFor === "هر دو") && ( +
+ +
+ )} + {(product.suitableFor === "گربه" || product.suitableFor === "هر دو") && ( +
+ +
+ )} +
-
- {product.symptoms.slice(0, 2).map((s, i) => ( - - {s} - - ))} -
+
+
{product.category}
+
+

+ {product.nameFa || product.name} +

+ {product.nameEn && ( + + {product.nameEn} + + )} +
-
- {product.price} - +
+ {product.symptoms.slice(0, 2).map((s, i) => ( + + {s} + + ))} +
+ +
+ {product.price} + +
-
+ ); -} +}; import { useRouter } from 'next/navigation'; @@ -491,7 +498,7 @@ export default function ArchivePage({
{filteredProducts.map((p: Product) => ( - router.push(`/shop/${p.slug || p.id}`)} /> + ))}
diff --git a/frontend/application/components/IngredientWiki.tsx b/frontend/application/components/IngredientWiki.tsx index 3c9862cc..2da18912 100644 --- a/frontend/application/components/IngredientWiki.tsx +++ b/frontend/application/components/IngredientWiki.tsx @@ -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() {
{hasIngredient.length > 0 ? hasIngredient.map(p => ( -
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" > {p.name}

{p.name}

-
+ )) : (

محصولی با این ماده مؤثره یافت نشد.

diff --git a/frontend/application/components/SearchResultsPage.tsx b/frontend/application/components/SearchResultsPage.tsx index 96d20cf7..8a975263 100644 --- a/frontend/application/components/SearchResultsPage.tsx +++ b/frontend/application/components/SearchResultsPage.tsx @@ -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 }) { 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" > -
- {product.nameFa - {product.specialBadge && ( -
- {product.specialBadge} -
- )} - {compatibility && ( -
- {compatibility.type === 'alert' ? : compatibility.type === 'success' ? : } - {compatibility.text} -
- )} -
- -
- {product.category} -

{product.nameFa || product.name}

-

{product.benefits}

-
- -
-
- {product.price} + +
+ {product.nameFa + {product.specialBadge && ( +
+ {product.specialBadge} +
+ )} + {compatibility && ( +
+ {compatibility.type === 'alert' ? : compatibility.type === 'success' ? : } + {compatibility.text} +
+ )}
- -
+ +
+ {product.category} +

{product.nameFa || product.name}

+

{product.benefits}

+
+ +
+
+ {product.price} +
+
+ +
+
+ ) })} @@ -124,12 +129,12 @@ export default function SearchResultsPage({ query }: { query: string }) {

محصولات پیشنهادی (پرفروش)

{bestSellers.map(p => ( -
router.push(`/shop/${p.id}`)} className="cursor-pointer group"> +

{p.name}

-
+ ))}