From 03d100905fc037e2d0468402824ed52775f535e5 Mon Sep 17 00:00:00 2001 From: parsa aghayi Date: Tue, 26 May 2026 11:44:14 +0330 Subject: [PATCH] refactor: optimize ArchivePage performance and imports Remove lazy loading for ArchivePage and update cart toast notifications to use direct imports. Refactor pet state selection in product cards for better reactivity. --- src/App.tsx | 3 ++- src/components/ArchivePage.tsx | 9 +++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 0d00299..e4c6c50 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -17,8 +17,9 @@ import { NotFoundPage } from './components/ErrorPages'; import { toast } from "sonner"; import labImage from "./assets/images/regenerated_image_1779109861747.png"; +import ArchivePage from "./components/ArchivePage"; + // Lazy Loaded Components -const ArchivePage = lazy(() => import("./components/ArchivePage")); const ProductPage = lazy(() => import("./components/ProductPage")); const PetProfile = lazy(() => import("./components/PetProfile")); const UserDashboard = lazy(() => import("./components/UserDashboard")); diff --git a/src/components/ArchivePage.tsx b/src/components/ArchivePage.tsx index df2826a..11730e7 100644 --- a/src/components/ArchivePage.tsx +++ b/src/components/ArchivePage.tsx @@ -4,6 +4,7 @@ import { usePetStore } from "../store/usePetStore"; import { productService } from "../services/productService"; import { motion, AnimatePresence } from "motion/react"; import { ProductCardSkeleton } from "./Skeleton"; +import { toast } from "sonner"; import { Search, Filter, @@ -68,19 +69,15 @@ const SYMPTOMS = [ ]; const ArchiveProductCard: React.FC<{ product: Product, onClick: (p: Product) => void }> = ({ product, onClick }) => { - const { getActivePet } = usePetStore(); const { addItem } = useCartStore(); const [isAdding, setIsAdding] = useState(false); - const activePet = getActivePet(); + const activePet = usePetStore(state => state.pets.find(p => p.id === state.activePetId) || null); const handleAddToCart = (e: React.MouseEvent) => { e.stopPropagation(); setIsAdding(true); addItem(product, 1); - // @ts-ignore - import("sonner").then(({ toast }) => { - toast.success(`${product.name} به سبد خرید اضافه شد`); - }); + toast.success(`${product.name} به سبد خرید اضافه شد`); setTimeout(() => setIsAdding(false), 800); };