feat(shop): mobile filter slider, list/card view toggle, and breadcrumb fixes
This commit is contained in:
1 parent
026c5b9086
commit
a9fbcbb90c
18 files changed
+157515
-7538
No files matched your search
@@ -7,7 +7,7 @@ import { productService } from "../lib/services/productService";
|
||||
import { isSuitableForDog, isSuitableForCat, isSuitableForBoth, isSpeciesCompatible, matchesMedicalSymptom } from "../lib/petCompatibility";
|
||||
import Link from "next/link";
|
||||
import { motion, AnimatePresence } from "motion/react";
|
||||
import { ProductCardSkeleton } from "./Skeleton";
|
||||
import { ProductCardSkeleton, ProductListSkeleton } from "./Skeleton";
|
||||
import { toast } from "sonner";
|
||||
import {
|
||||
Search,
|
||||
@@ -16,7 +16,6 @@ import {
|
||||
Cat,
|
||||
ShieldCheck,
|
||||
ChevronLeft,
|
||||
ChevronRight,
|
||||
Activity,
|
||||
Sparkles,
|
||||
Stethoscope,
|
||||
@@ -24,7 +23,11 @@ import {
|
||||
Heart,
|
||||
AlertCircle,
|
||||
Plus,
|
||||
Loader2
|
||||
Loader2,
|
||||
LayoutGrid,
|
||||
List,
|
||||
SlidersHorizontal,
|
||||
ChevronDown
|
||||
} from "lucide-react";
|
||||
import { useCartStore } from "../lib/store/cartStore";
|
||||
import { useSettingsStore } from "../lib/store/settingsStore";
|
||||
@@ -250,6 +253,176 @@ const ArchiveProductCard: React.FC<{ product: Product }> = ({ product }) => {
|
||||
);
|
||||
};
|
||||
|
||||
const ArchiveProductListItem: React.FC<{ product: Product }> = ({ product }) => {
|
||||
const { addItem } = useCartStore();
|
||||
const cartItem = useCartStore((s) => s.items.find(i => i.product.id === product.id));
|
||||
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);
|
||||
toast.success(`${product.name} به سبد خرید اضافه شد`);
|
||||
setTimeout(() => setIsAdding(false), 400);
|
||||
};
|
||||
|
||||
const forDog = isSuitableForDog(product.suitableFor);
|
||||
const forCat = isSuitableForCat(product.suitableFor);
|
||||
|
||||
const compatibility = useMemo(() => {
|
||||
if (!activePet) return null;
|
||||
|
||||
const sameSpecies = isSpeciesCompatible(product.suitableFor, activePet.type);
|
||||
const matchedSymptom = matchesMedicalSymptom(activePet.medicalConditions, product.symptoms, product.benefits);
|
||||
|
||||
if (!sameSpecies) return { type: 'alert', text: `مخصوص ${product.suitableFor}` };
|
||||
if (matchedSymptom) return { type: 'success', text: `توصیه شده برای ${matchedSymptom} ${activePet.name}` };
|
||||
if (sameSpecies) return { type: 'neutral', text: `مناسب برای ${activePet.name}` };
|
||||
|
||||
return null;
|
||||
}, [product, activePet]);
|
||||
|
||||
const isOutOfStock = (product.packageSize !== undefined && product.packageSize !== null ? Number(product.packageSize) : 100) <= 0;
|
||||
const hidePrices = useSettingsStore.getState().getText("catalog_hide_prices", "false").includes("true");
|
||||
const disableCart = useSettingsStore.getState().getText("catalog_disable_cart", "false").includes("true");
|
||||
|
||||
return (
|
||||
<motion.div
|
||||
layout
|
||||
initial={{ opacity: 0, y: 10 }}
|
||||
animate={{ opacity: 1, y: 0 }}
|
||||
className="w-full"
|
||||
>
|
||||
<Link
|
||||
data-testid="archive-product-list-item"
|
||||
href={productUrl}
|
||||
className="group bg-white rounded-2xl border border-medical-gray-200 overflow-hidden hover:border-canina-blue/30 transition-all flex items-center p-2.5 gap-3 relative shadow-xs"
|
||||
>
|
||||
{/* Product Thumbnail with species badge */}
|
||||
<div className="w-24 h-24 sm:w-28 sm:h-28 bg-medical-gray-50 rounded-xl flex-shrink-0 flex items-center justify-center p-1 relative overflow-hidden border border-medical-gray-100">
|
||||
<SafeImage
|
||||
src={product.image}
|
||||
alt={product.name}
|
||||
sizes="120px"
|
||||
className="w-full h-full group-hover:scale-105 transition-transform duration-500"
|
||||
imgClassName="w-full h-full object-contain"
|
||||
/>
|
||||
{product.specialBadge && (
|
||||
<div className="absolute top-1 right-1 z-10 bg-canina-blue text-white text-[9px] font-black uppercase px-1.5 py-0.5 rounded-md shadow-xs">
|
||||
{product.specialBadge}
|
||||
</div>
|
||||
)}
|
||||
<div className="absolute bottom-1 left-1 flex gap-1">
|
||||
{forDog && (
|
||||
<div className="w-5 h-5 bg-white/90 backdrop-blur-xs rounded-md flex items-center justify-center text-medical-gray-500 border border-medical-gray-100 shadow-2xs" title="مناسب برای سگ">
|
||||
<Dog className="w-3 h-3" />
|
||||
</div>
|
||||
)}
|
||||
{forCat && (
|
||||
<div className="w-5 h-5 bg-white/90 backdrop-blur-xs rounded-md flex items-center justify-center text-medical-gray-500 border border-medical-gray-100 shadow-2xs" title="مناسب برای گربه">
|
||||
<Cat className="w-3 h-3" />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Product Info */}
|
||||
<div className="flex-1 flex flex-col justify-between self-stretch min-w-0 py-0.5">
|
||||
<div>
|
||||
<div className="flex items-center gap-1.5 mb-1">
|
||||
<span className="text-[10px] font-bold text-canina-blue truncate">{product.category}</span>
|
||||
{compatibility && (
|
||||
<span className={`text-[9px] font-black px-1.5 py-0.2 rounded-md ${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.text}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<h3 dir="rtl" className="text-xs sm:text-sm font-black text-medical-gray-900 group-hover:text-canina-blue transition-colors leading-snug text-right font-vazir line-clamp-2">
|
||||
{product.nameFa || product.name}
|
||||
</h3>
|
||||
{product.nameEn && (
|
||||
<span dir="ltr" className="text-[10px] font-semibold text-slate-400 font-sans text-left block truncate mt-0.5">
|
||||
{product.nameEn}
|
||||
</span>
|
||||
)}
|
||||
|
||||
{product.symptoms && product.symptoms.length > 0 && (
|
||||
<div className="flex flex-wrap gap-1 mt-1.5">
|
||||
{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-1.5 py-0.5 rounded">
|
||||
{s}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Price & Add to Cart */}
|
||||
<div className="mt-2 flex items-center justify-between pt-2 border-t border-medical-gray-100/70 gap-2">
|
||||
{!hidePrices ? (
|
||||
<span className="font-black text-medical-gray-900 font-vazir text-xs sm:text-sm">{product.price}</span>
|
||||
) : (
|
||||
<span className="text-[10px] font-bold text-amber-600 bg-amber-50 px-1.5 py-0.5 rounded">استعلام قیمت</span>
|
||||
)}
|
||||
|
||||
{isOutOfStock ? (
|
||||
<span className="px-2 py-1 rounded-lg bg-rose-50 text-rose-600 border border-rose-100 text-[10px] font-bold font-vazir">
|
||||
ناموجود
|
||||
</span>
|
||||
) : !disableCart && (
|
||||
cartItem && cartItem.quantity > 0 ? (
|
||||
<div
|
||||
onClick={(e) => { e.preventDefault(); e.stopPropagation(); }}
|
||||
className="flex items-center gap-1 bg-canina-blue/10 border border-canina-blue/20 rounded-lg p-0.5"
|
||||
>
|
||||
<button
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
useCartStore.getState().updateQuantity(product.id, cartItem.quantity + 1);
|
||||
}}
|
||||
className="w-6 h-6 rounded-md bg-canina-blue text-white flex items-center justify-center font-bold text-xs"
|
||||
>
|
||||
+
|
||||
</button>
|
||||
<span className="w-4 text-center font-black text-canina-blue text-xs font-vazir">
|
||||
{toPersian(cartItem.quantity)}
|
||||
</span>
|
||||
<button
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
useCartStore.getState().updateQuantity(product.id, cartItem.quantity - 1);
|
||||
}}
|
||||
className="w-6 h-6 rounded-md bg-white text-medical-gray-700 flex items-center justify-center font-bold text-xs shadow-2xs"
|
||||
>
|
||||
-
|
||||
</button>
|
||||
</div>
|
||||
) : (
|
||||
<button
|
||||
onClick={handleAddToCart}
|
||||
disabled={isAdding}
|
||||
className="px-2.5 py-1.5 rounded-lg bg-canina-blue text-white text-[11px] font-black flex items-center gap-1 hover:bg-canina-dark transition-all disabled:opacity-50 shadow-xs shadow-canina-blue/20"
|
||||
>
|
||||
{isAdding ? <Loader2 className="w-3 h-3 animate-spin" /> : <Plus className="w-3 h-3" />}
|
||||
<span>خرید</span>
|
||||
</button>
|
||||
)
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</Link>
|
||||
</motion.div>
|
||||
);
|
||||
};
|
||||
|
||||
import { useRouter } from 'next/navigation';
|
||||
|
||||
export default function ArchivePage({
|
||||
@@ -270,10 +443,12 @@ export default function ArchivePage({
|
||||
const [activeSymptoms, setActiveSymptoms] = useState<string[]>(initialSymptoms ? initialSymptoms.split(',') : []);
|
||||
const [searchQuery, setSearchQuery] = useState(initialSearch);
|
||||
const [isUpdating, setIsUpdating] = useState(false);
|
||||
const [isMobileFilterOpen, setIsMobileFilterOpen] = useState(false);
|
||||
const [filteredProducts, setFilteredProducts] = useState<Product[]>([]);
|
||||
const [sortBy, setSortBy] = useState<string>("createdAt");
|
||||
const [sortOrder, setSortOrder] = useState<"asc" | "desc">("desc");
|
||||
const [viewMode, setViewMode] = useState<"list" | "grid">("list");
|
||||
const [isMobileSolutionsOpen, setIsMobileSolutionsOpen] = useState(false);
|
||||
const [isMobileSymptomsOpen, setIsMobileSymptomsOpen] = useState(false);
|
||||
|
||||
const [symptomSearch, setSymptomSearch] = useState("");
|
||||
const [categories, setCategories] = useState<{ id: string; label: string; icon: React.ReactNode }[]>([]);
|
||||
@@ -408,8 +583,8 @@ export default function ArchivePage({
|
||||
<div className="flex items-center justify-between mb-8 pb-4 border-b border-medical-gray-200/60 font-vazir gap-2" dir="rtl">
|
||||
{/* Breadcrumb - right side in RTL */}
|
||||
<div className="flex items-center gap-1.5 text-xs font-bold text-medical-gray-400 overflow-hidden min-w-0">
|
||||
<span className="hidden sm:inline cursor-pointer hover:text-canina-blue transition-colors shrink-0" onClick={() => router.push('/')}>خانه</span>
|
||||
<ChevronLeft className="hidden sm:block w-3 h-3 text-medical-gray-300 shrink-0" />
|
||||
<span className="cursor-pointer hover:text-canina-blue transition-colors shrink-0" onClick={() => router.push('/')}>خانه</span>
|
||||
<ChevronLeft className="w-3 h-3 text-medical-gray-300 shrink-0" />
|
||||
<span className="cursor-pointer hover:text-canina-blue transition-colors shrink-0" onClick={() => { setSelectedCategory("all"); }}>فروشگاه محصولات</span>
|
||||
{selectedCategory !== "all" && (
|
||||
<>
|
||||
@@ -420,15 +595,6 @@ export default function ArchivePage({
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-2 shrink-0">
|
||||
{/* Mobile Filter Button */}
|
||||
<button
|
||||
onClick={() => setIsMobileFilterOpen(!isMobileFilterOpen)}
|
||||
className="lg:hidden flex-shrink-0 flex items-center gap-1.5 bg-canina-blue text-white px-3 py-1.5 rounded-lg text-xs font-bold shadow-xs cursor-pointer"
|
||||
>
|
||||
<Filter className="w-3.5 h-3.5" />
|
||||
<span>فیلترها {activeSymptoms.length > 0 || selectedPet !== "all" || selectedCategory !== "all" ? "•" : ""}</span>
|
||||
</button>
|
||||
|
||||
{/* Back Button - leftmost in RTL */}
|
||||
<button
|
||||
onClick={() => router.push('/')}
|
||||
@@ -445,28 +611,14 @@ export default function ArchivePage({
|
||||
|
||||
<div className="flex flex-col lg:flex-row gap-8">
|
||||
|
||||
{/* Mobile Overlay Backdrop */}
|
||||
{isMobileFilterOpen && (
|
||||
<div
|
||||
className="lg:hidden fixed inset-0 bg-black/50 z-40 backdrop-blur-xs transition-opacity"
|
||||
onClick={() => setIsMobileFilterOpen(false)}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* Sidebar Filters - Collapsible on Mobile */}
|
||||
<aside className={`lg:w-72 flex-shrink-0 space-y-6 ${isMobileFilterOpen ? 'fixed inset-y-0 right-0 z-50 w-4/5 max-w-xs bg-white p-6 overflow-y-auto shadow-2xl space-y-6' : 'hidden lg:block'}`}>
|
||||
{/* Sidebar Filters - Desktop only */}
|
||||
<aside className="lg:w-72 flex-shrink-0 space-y-6 hidden lg:block">
|
||||
<div className="bg-white rounded-[2rem] lg:p-6 border-0 lg:border lg:border-medical-gray-200 shadow-none lg:shadow-sm">
|
||||
<div className="flex items-center justify-between mb-6">
|
||||
<div className="flex items-center gap-2">
|
||||
<Filter className="w-5 h-5 text-canina-blue" />
|
||||
<h3 className="font-black text-medical-gray-900">{getText('shop_filter_title', 'فیلترهای تخصصی')}</h3>
|
||||
</div>
|
||||
<button
|
||||
onClick={() => setIsMobileFilterOpen(false)}
|
||||
className="lg:hidden text-xs text-medical-gray-400 font-bold p-1 hover:text-red-500"
|
||||
>
|
||||
بستن ✕
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="space-y-6">
|
||||
@@ -498,7 +650,7 @@ export default function ArchivePage({
|
||||
{categories.map(cat => (
|
||||
<button
|
||||
key={cat.id}
|
||||
onClick={() => { setSelectedCategory(cat.id); setIsMobileFilterOpen(false); }}
|
||||
onClick={() => setSelectedCategory(cat.id)}
|
||||
className={`flex items-center gap-3 px-4 py-3 rounded-2xl text-xs font-bold transition-all border ${selectedCategory === cat.id ? 'bg-canina-blue border-canina-blue text-white' : 'bg-white border-medical-gray-100 text-medical-gray-600 hover:border-canina-blue/30'}`}
|
||||
>
|
||||
{cat.icon}
|
||||
@@ -568,8 +720,9 @@ export default function ArchivePage({
|
||||
|
||||
{/* Main Content */}
|
||||
<main className="flex-1 relative">
|
||||
<div className="flex flex-col sm:flex-row items-center justify-between mb-6 gap-4">
|
||||
{getText('shop_catalog_title', 'کاتولوگ دارویی Canina') ? (
|
||||
{/* Desktop Top Title & Search / Sort Row */}
|
||||
<div className="hidden lg:flex flex-col sm:flex-row items-center justify-between mb-6 gap-4">
|
||||
{getText('shop_catalog_title', '').trim() ? (
|
||||
<h2
|
||||
className="text-3xl font-black text-medical-gray-900"
|
||||
dangerouslySetInnerHTML={{
|
||||
@@ -578,7 +731,7 @@ export default function ArchivePage({
|
||||
/>
|
||||
) : null}
|
||||
|
||||
<div className="flex flex-wrap sm:flex-nowrap items-center gap-3 w-full sm:w-auto">
|
||||
<div className="flex items-center gap-3 w-auto">
|
||||
{/* Sort Dropdown */}
|
||||
<div className="flex items-center gap-2 bg-white border border-medical-gray-200 rounded-2xl px-3 py-2 text-xs font-bold shadow-xs">
|
||||
<span className="text-medical-gray-400 whitespace-nowrap">مرتبسازی:</span>
|
||||
@@ -599,7 +752,7 @@ export default function ArchivePage({
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div className="relative w-full sm:w-64">
|
||||
<div className="relative w-64">
|
||||
<Search className="absolute right-4 top-1/2 -translate-y-1/2 w-4 h-4 text-medical-gray-400" />
|
||||
<input
|
||||
data-testid="shop-search-input"
|
||||
@@ -613,9 +766,213 @@ export default function ArchivePage({
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Mobile Title (Only if set in admin) */}
|
||||
{getText('shop_catalog_title', '').trim() ? (
|
||||
<div className="lg:hidden mb-4">
|
||||
<h2
|
||||
className="text-2xl font-black text-medical-gray-900"
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: getText('shop_catalog_title', 'کاتولوگ دارویی <span class="text-canina-blue">Canina</span>')
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{/* Mobile Controls: Horizontal Sliding Filters & View Toggle Row */}
|
||||
<div className="lg:hidden flex flex-col gap-3 mb-5">
|
||||
{/* Search Bar on Mobile */}
|
||||
<div className="relative w-full">
|
||||
<Search className="absolute right-4 top-1/2 -translate-y-1/2 w-4 h-4 text-medical-gray-400" />
|
||||
<input
|
||||
data-testid="shop-search-input-mobile"
|
||||
type="text"
|
||||
placeholder="جستجوی محصول..."
|
||||
value={searchQuery}
|
||||
onChange={(e) => setSearchQuery(e.target.value)}
|
||||
className="w-full bg-white border border-medical-gray-200 rounded-2xl py-2.5 pr-11 pl-4 text-xs font-bold focus:outline-none focus:ring-2 focus:ring-canina-blue/20 shadow-2xs"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Horizontal Scrollable Row for Sort, Pet Type, Solutions & Symptoms Filter */}
|
||||
<div className="flex items-center gap-2 overflow-x-auto pb-1.5 pt-0.5 scrollbar-none no-scrollbar -mx-4 px-4 select-none touch-pan-x">
|
||||
{/* 1. Compact Sort Button */}
|
||||
<div className="relative flex-shrink-0">
|
||||
<div className="flex items-center bg-white border border-medical-gray-200 rounded-xl px-2.5 py-1.5 shadow-2xs text-xs font-bold text-medical-gray-700">
|
||||
<SlidersHorizontal className="w-3.5 h-3.5 text-canina-blue ml-1.5 shrink-0" />
|
||||
<select
|
||||
value={`${sortBy}:${sortOrder}`}
|
||||
onChange={(e) => {
|
||||
const [b, o] = e.target.value.split(':');
|
||||
setSortBy(b);
|
||||
setSortOrder(o as 'asc' | 'desc');
|
||||
}}
|
||||
className="bg-transparent text-[11px] font-black text-medical-gray-800 outline-none cursor-pointer pr-1"
|
||||
>
|
||||
<option value="createdAt:desc">جدیدترین</option>
|
||||
<option value="createdAt:asc">قدیمیترین</option>
|
||||
<option value="priceValue:asc">ارزانترین</option>
|
||||
<option value="priceValue:desc">گرانترین</option>
|
||||
<option value="nameFa:asc">الف - ی</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 2. Three Segmented Pet Type Buttons (Dog right, Both middle, Cat left) */}
|
||||
<div className="flex-shrink-0 inline-flex items-center bg-white border border-medical-gray-200 rounded-xl p-0.5 shadow-2xs">
|
||||
{/* Right: Dog */}
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setSelectedPet("سگ")}
|
||||
className={`flex items-center gap-1 px-2.5 py-1 rounded-lg text-[11px] font-black transition-all ${selectedPet === "سگ" ? "bg-canina-blue text-white shadow-xs" : "text-medical-gray-500 hover:text-medical-gray-800"}`}
|
||||
>
|
||||
<Dog className="w-3.5 h-3.5" />
|
||||
<span>سگ</span>
|
||||
</button>
|
||||
|
||||
{/* Middle: Both */}
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setSelectedPet("all")}
|
||||
className={`flex items-center gap-1 px-2.5 py-1 rounded-lg text-[11px] font-black transition-all ${selectedPet === "all" ? "bg-canina-blue text-white shadow-xs" : "text-medical-gray-500 hover:text-medical-gray-800"}`}
|
||||
>
|
||||
<Activity className="w-3.5 h-3.5" />
|
||||
<span>هردو</span>
|
||||
</button>
|
||||
|
||||
{/* Left: Cat */}
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setSelectedPet("گربه")}
|
||||
className={`flex items-center gap-1 px-2.5 py-1 rounded-lg text-[11px] font-black transition-all ${selectedPet === "گربه" ? "bg-canina-blue text-white shadow-xs" : "text-medical-gray-500 hover:text-medical-gray-800"}`}
|
||||
>
|
||||
<Cat className="w-3.5 h-3.5" />
|
||||
<span>گربه</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* 3. Solutions Dropdown Button */}
|
||||
<div className="relative flex-shrink-0">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setIsMobileSolutionsOpen(!isMobileSolutionsOpen);
|
||||
setIsMobileSymptomsOpen(false);
|
||||
}}
|
||||
className={`flex items-center gap-1.5 px-3 py-1.5 rounded-xl border text-[11px] font-black shadow-2xs transition-all whitespace-nowrap ${selectedCategory !== "all" ? "bg-canina-blue text-white border-canina-blue" : "bg-white border-medical-gray-200 text-medical-gray-700"}`}
|
||||
>
|
||||
<span>{selectedCategory !== "all" ? (CATEGORY_LABELS[selectedCategory] || "راهکار درمانی") : "راهکار درمانی"}</span>
|
||||
<ChevronDown className={`w-3 h-3 transition-transform ${isMobileSolutionsOpen ? "rotate-180" : ""}`} />
|
||||
</button>
|
||||
|
||||
{isMobileSolutionsOpen && (
|
||||
<>
|
||||
<div className="fixed inset-0 z-40" onClick={() => setIsMobileSolutionsOpen(false)} />
|
||||
<div className="absolute right-0 top-full mt-2 w-64 max-h-72 overflow-y-auto bg-white rounded-2xl p-2 border border-medical-gray-200 shadow-xl z-50 space-y-1 font-vazir">
|
||||
{categories.map(cat => (
|
||||
<button
|
||||
key={cat.id}
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setSelectedCategory(cat.id);
|
||||
setIsMobileSolutionsOpen(false);
|
||||
}}
|
||||
className={`w-full flex items-center gap-2.5 px-3 py-2 rounded-xl text-xs font-bold text-right transition-colors ${selectedCategory === cat.id ? "bg-canina-blue text-white" : "hover:bg-medical-gray-50 text-medical-gray-700"}`}
|
||||
>
|
||||
<span className="shrink-0">{cat.icon}</span>
|
||||
<span className="truncate">{cat.label}</span>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* 4. Symptoms Dropdown Button with search inside */}
|
||||
<div className="relative flex-shrink-0">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setIsMobileSymptomsOpen(!isMobileSymptomsOpen);
|
||||
setIsMobileSolutionsOpen(false);
|
||||
}}
|
||||
className={`flex items-center gap-1.5 px-3 py-1.5 rounded-xl border text-[11px] font-black shadow-2xs transition-all whitespace-nowrap ${activeSymptoms.length > 0 ? "bg-canina-blue text-white border-canina-blue" : "bg-white border-medical-gray-200 text-medical-gray-700"}`}
|
||||
>
|
||||
<span>علائم پت {activeSymptoms.length > 0 ? `(${toPersian(activeSymptoms.length)})` : ""}</span>
|
||||
<ChevronDown className={`w-3 h-3 transition-transform ${isMobileSymptomsOpen ? "rotate-180" : ""}`} />
|
||||
</button>
|
||||
|
||||
{isMobileSymptomsOpen && (
|
||||
<>
|
||||
<div className="fixed inset-0 z-40" onClick={() => setIsMobileSymptomsOpen(false)} />
|
||||
<div className="absolute right-0 top-full mt-2 w-72 max-h-80 overflow-y-auto bg-white rounded-2xl p-3 border border-medical-gray-200 shadow-xl z-50 font-vazir">
|
||||
<div className="flex items-center justify-between mb-2 pb-1 border-b border-medical-gray-100">
|
||||
<span className="text-[10px] font-black text-medical-gray-400">جستجو بر اساس علائم</span>
|
||||
{activeSymptoms.length > 0 && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setActiveSymptoms([])}
|
||||
className="text-[10px] font-bold text-red-500 hover:underline"
|
||||
>
|
||||
پاک کردن همه
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="جستجوی علائم..."
|
||||
value={symptomSearch}
|
||||
onChange={(e) => setSymptomSearch(e.target.value)}
|
||||
className="w-full bg-medical-gray-50 border border-medical-gray-200 rounded-xl py-1.5 px-2.5 text-xs outline-none focus:border-canina-blue mb-2.5 font-vazir"
|
||||
/>
|
||||
<div className="flex flex-wrap gap-1.5 max-h-48 overflow-y-auto scrollbar-thin pr-0.5">
|
||||
{symptoms.length === 0 ? (
|
||||
<span className="text-[10px] text-medical-gray-400">در حال بارگذاری...</span>
|
||||
) : symptoms
|
||||
.filter(s => s.toLowerCase().includes(symptomSearch.toLowerCase()))
|
||||
.map(s => (
|
||||
<button
|
||||
key={s}
|
||||
type="button"
|
||||
onClick={() => toggleSymptom(s)}
|
||||
className={`px-2.5 py-1 rounded-lg text-[10px] font-bold transition-all border whitespace-nowrap ${activeSymptoms.includes(s)
|
||||
? "bg-canina-blue border-canina-blue text-white shadow-2xs"
|
||||
: "bg-medical-gray-50 border-medical-gray-200 text-medical-gray-600 hover:border-canina-blue/40 hover:text-canina-blue"
|
||||
}`}
|
||||
>
|
||||
{s}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* 5. View Mode Switch: 2 Buttons (List / Card) */}
|
||||
<div className="flex-shrink-0 inline-flex items-center bg-white border border-medical-gray-200 rounded-xl p-0.5 shadow-2xs mr-auto">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setViewMode("list")}
|
||||
className={`p-1.5 rounded-lg transition-all ${viewMode === "list" ? "bg-canina-blue text-white shadow-xs" : "text-medical-gray-400 hover:text-medical-gray-700"}`}
|
||||
title="نمایش لیستی"
|
||||
>
|
||||
<List className="w-3.5 h-3.5" />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setViewMode("grid")}
|
||||
className={`p-1.5 rounded-lg transition-all ${viewMode === "grid" ? "bg-canina-blue text-white shadow-xs" : "text-medical-gray-400 hover:text-medical-gray-700"}`}
|
||||
title="نمایش کارتی"
|
||||
>
|
||||
<LayoutGrid className="w-3.5 h-3.5" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Active Filters Bar with X Dismiss Cross Buttons */}
|
||||
{(selectedCategory !== "all" || selectedPet !== "all" || activeSymptoms.length > 0 || searchQuery) && (
|
||||
<div className="flex flex-wrap items-center gap-2 mb-6 bg-white p-4 rounded-2xl border border-medical-gray-200 shadow-sm font-vazir" dir="rtl">
|
||||
<div className="flex flex-wrap items-center gap-2 mb-6 bg-white p-3 sm:p-4 rounded-2xl border border-medical-gray-200 shadow-sm font-vazir" dir="rtl">
|
||||
<span className="text-xs font-black text-medical-gray-400 ml-2">فیلترهای فعال:</span>
|
||||
{selectedCategory !== "all" && (
|
||||
<span className="inline-flex items-center gap-1.5 px-3 py-1 bg-canina-blue/10 text-canina-blue rounded-xl text-xs font-black border border-canina-blue/20">
|
||||
@@ -652,17 +1009,47 @@ export default function ArchivePage({
|
||||
|
||||
<AnimatePresence mode="wait">
|
||||
{isUpdating ? (
|
||||
<div key="skeleton" className="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-4 gap-6">
|
||||
{Array.from({ length: 8 }).map((_, i) => (
|
||||
<ProductCardSkeleton key={i} />
|
||||
))}
|
||||
</div>
|
||||
viewMode === "list" ? (
|
||||
<div key="skeleton-list" className="flex flex-col gap-3 lg:hidden">
|
||||
{Array.from({ length: 8 }).map((_, i) => (
|
||||
<ProductListSkeleton key={i} />
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<div key="skeleton-grid" className="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-4 gap-6">
|
||||
{Array.from({ length: 8 }).map((_, i) => (
|
||||
<ProductCardSkeleton key={i} />
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
) : filteredProducts.length > 0 ? (
|
||||
<>
|
||||
<div key="grid" className="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-4 gap-6">
|
||||
{/* Mobile List View vs Card View (Desktop is always responsive multi-column grid) */}
|
||||
<div
|
||||
key={viewMode}
|
||||
className={
|
||||
viewMode === "list"
|
||||
? "flex flex-col gap-3 lg:grid lg:grid-cols-2 xl:grid-cols-4 lg:gap-6"
|
||||
: "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} />
|
||||
<React.Fragment key={p.id}>
|
||||
{/* In list mode on mobile, render ArchiveProductListItem; on desktop (lg+), render standard card */}
|
||||
{viewMode === "list" ? (
|
||||
<>
|
||||
<div className="block lg:hidden w-full">
|
||||
<ArchiveProductListItem product={p} />
|
||||
</div>
|
||||
<div className="hidden lg:block h-full">
|
||||
<ArchiveProductCard product={p} />
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<ArchiveProductCard product={p} />
|
||||
)}
|
||||
</React.Fragment>
|
||||
))}
|
||||
</AnimatePresence>
|
||||
</div>
|
||||
|
||||
@@ -47,8 +47,8 @@ export default function BrandLogo({
|
||||
<Image
|
||||
src={logoUrl}
|
||||
alt={`${textEn} ${textFa}`}
|
||||
width={180}
|
||||
height={48}
|
||||
width={140}
|
||||
height={50}
|
||||
priority
|
||||
unoptimized={isBlobOrData}
|
||||
className="h-10 sm:h-12 w-auto max-w-[160px] sm:max-w-[200px] object-contain shrink-0"
|
||||
|
||||
@@ -209,7 +209,7 @@ export default function Header({
|
||||
{/* Sliding Announcement Ticker Banner */}
|
||||
<TickerBanner />
|
||||
|
||||
<header className="bg-white border-b border-medical-gray-200">
|
||||
<header className="bg-white border-b border-medical-gray-200 overflow-hidden">
|
||||
{/* TOP ROW: Logo + Search + Primary Actions */}
|
||||
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-3 flex items-center justify-between gap-4">
|
||||
|
||||
|
||||
@@ -138,19 +138,7 @@ export default function Hero({ banners = [], onShopNavigate }: { banners?: Banne
|
||||
}}
|
||||
/>
|
||||
|
||||
<div className="whitespace-nowrap flex flex-nowrap justify-center lg:justify-start gap-2 sm:gap-4 sm:gap-6 min-h-[58px]">
|
||||
<button
|
||||
onClick={() => {
|
||||
const element = document.getElementById('canino-advisor');
|
||||
if (element) {
|
||||
element.scrollIntoView({ behavior: 'smooth' });
|
||||
}
|
||||
}}
|
||||
className="bg-canina-blue text-white px-3 sm:px-10 py-2 sm:py-5 rounded-full font-bold text-lg hover:bg-canina-blue/90 hover:shadow-2xl focus-visible:ring-4 focus-visible:ring-canina-blue/30 focus-visible:outline-none transition-all flex items-center gap-2 group font-vazir min-h-[58px] shadow-lg shadow-canina-blue/20 cursor-pointer"
|
||||
>
|
||||
<span suppressHydrationWarning>{mounted && isInitialized ? getText('hero_btn_advisor', "دستیار سلامت پت") : "دستیار سلامت پت"}</span>
|
||||
<ChevronLeft className="w-5 h-5 group-hover:-translate-x-1 transition-transform" />
|
||||
</button>
|
||||
<div className="whitespace-nowrap flex flex-nowrap justify-center lg:justify-start gap-2 sm:gap-6">
|
||||
<button
|
||||
onClick={() => {
|
||||
if (onShopNavigate) {
|
||||
@@ -159,9 +147,23 @@ export default function Hero({ banners = [], onShopNavigate }: { banners?: Banne
|
||||
router.push('/shop');
|
||||
}
|
||||
}}
|
||||
className="bg-white border-2 border-medical-gray-900 text-medical-gray-900 px-3 sm:px-10 py-2 sm:py-5 rounded-full font-bold text-lg hover:bg-medical-gray-50 focus-visible:ring-4 focus-visible:ring-canina-blue/30 focus-visible:outline-none transition-all font-vazir min-h-[58px] shadow-sm cursor-pointer"
|
||||
className="bg-canina-blue text-white px-3 sm:px-10 py-2 sm:py-5 rounded-full font-bold text-lg hover:bg-canina-blue/90 hover:shadow-2xl focus-visible:ring-4 focus-visible:ring-canina-blue/30 focus-visible:outline-none transition-all gap-2 group font-vazir shadow-lg shadow-canina-blue/20 cursor-pointer"
|
||||
>
|
||||
|
||||
<span suppressHydrationWarning>{mounted && isInitialized ? getText('hero_btn_products', "مشاهده محصولات") : "مشاهده محصولات"}</span>
|
||||
|
||||
</button>
|
||||
<button
|
||||
onClick={() => {
|
||||
const element = document.getElementById('canino-advisor');
|
||||
if (element) {
|
||||
element.scrollIntoView({ behavior: 'smooth' });
|
||||
}
|
||||
}}
|
||||
className="flex items-center bg-white border-2 border-medical-gray-900 text-medical-gray-900 px-3 sm:px-10 py-2 sm:py-5 rounded-full font-bold text-lg hover:bg-medical-gray-50 focus-visible:ring-4 focus-visible:ring-canina-blue/30 focus-visible:outline-none transition-all font-vazir shadow-sm cursor-pointer"
|
||||
>
|
||||
<span suppressHydrationWarning>{mounted && isInitialized ? getText('hero_btn_advisor', "دستیار سلامت پت") : "دستیار سلامت پت"}</span>
|
||||
<ChevronLeft className="w-5 h-5 group-hover:-translate-x-1 transition-transform" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -270,11 +272,10 @@ export default function Hero({ banners = [], onShopNavigate }: { banners?: Banne
|
||||
aria-label={`رفتن به اسلاید ${idx + 1}`}
|
||||
>
|
||||
<span
|
||||
className={`block rounded-full transition-opacity duration-300 ${
|
||||
currentSlide === idx
|
||||
className={`block rounded-full transition-opacity duration-300 ${currentSlide === idx
|
||||
? "w-4 h-2 bg-canina-gold opacity-100"
|
||||
: "w-2 h-2 bg-white opacity-60 hover:opacity-100"
|
||||
}`}
|
||||
}`}
|
||||
/>
|
||||
</button>
|
||||
))}
|
||||
|
||||
@@ -40,6 +40,25 @@ export const ProductCardSkeleton = () => {
|
||||
);
|
||||
};
|
||||
|
||||
export const ProductListSkeleton = () => {
|
||||
return (
|
||||
<div className="bg-white rounded-2xl p-3 border border-medical-gray-100 shadow-xs flex items-center gap-3">
|
||||
<Skeleton className="w-24 h-24 rounded-xl flex-shrink-0" />
|
||||
<div className="flex-1 flex flex-col justify-between self-stretch py-0.5 min-w-0">
|
||||
<div className="space-y-1.5">
|
||||
<Skeleton className="w-16 h-3 rounded-full" />
|
||||
<Skeleton className="w-4/5 h-4 rounded-md" />
|
||||
<Skeleton className="w-1/2 h-3 rounded-md" />
|
||||
</div>
|
||||
<div className="flex items-center justify-between pt-2 border-t border-medical-gray-50">
|
||||
<Skeleton className="w-20 h-4 rounded-md" />
|
||||
<Skeleton className="w-16 h-7 rounded-lg" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export const PetProfileSkeleton = () => {
|
||||
return (
|
||||
<div className="bg-white rounded-[3rem] p-10 shadow-2xl border border-medical-gray-50">
|
||||
|
||||
Reference in new issue
Block a user