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.
This commit is contained in:
پارسا آقایی 2026-05-26 11:44:14 +03:30
parent 29ba592366
commit 03d100905f
2 changed files with 5 additions and 7 deletions

View File

@ -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"));

View File

@ -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);
};