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:
parent
29ba592366
commit
03d100905f
@ -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"));
|
||||
|
||||
@ -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} به سبد خرید اضافه شد`);
|
||||
});
|
||||
setTimeout(() => setIsAdding(false), 800);
|
||||
};
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user