diff --git a/src/app/[name]/(Main)/components/MenuSkeleton.tsx b/src/app/[name]/(Main)/components/MenuSkeleton.tsx index 19dfb2a..89362f5 100644 --- a/src/app/[name]/(Main)/components/MenuSkeleton.tsx +++ b/src/app/[name]/(Main)/components/MenuSkeleton.tsx @@ -1,15 +1,15 @@ -'use client'; +"use client"; -import { Skeleton } from "@/components/ui/skeleton"; -import VerticalScrollView from "@/components/listview/VerticalScrollView"; -import MenuItemRenderer from "@/components/listview/MenuItemRenderer"; import type { MenuItemViewMode } from "@/components/listview/MenuItem"; +import MenuItemRenderer from "@/components/listview/MenuItemRenderer"; +import VerticalScrollView from "@/components/listview/VerticalScrollView"; +import { Skeleton } from "@/components/ui/skeleton"; interface MenuSkeletonProps { viewMode?: MenuItemViewMode; } -const MenuSkeleton = ({ viewMode = 'list' }: MenuSkeletonProps) => { +const MenuSkeleton = ({ viewMode = "list" }: MenuSkeletonProps) => { return (
@@ -31,7 +31,7 @@ const MenuSkeleton = ({ viewMode = 'list' }: MenuSkeletonProps) => {
- {viewMode === 'grid' ? ( + {viewMode === "grid" ? (
{[...Array(6)].map((_, index) => ( @@ -52,20 +52,18 @@ const MenuSkeleton = ({ viewMode = 'list' }: MenuSkeletonProps) => { ) : ( [...Array(6)].map((_, index) => ( -
- -
+
+ +
-
-
- -
- -
+ +
+
+
diff --git a/src/components/listview/MenuItem.tsx b/src/components/listview/MenuItem.tsx index d4fb1a1..c5d6fa3 100644 --- a/src/components/listview/MenuItem.tsx +++ b/src/components/listview/MenuItem.tsx @@ -1,19 +1,16 @@ /* eslint-disable @next/next/no-img-element */ -'use client' +"use client"; -import { memo, useMemo } from "react"; -import Link from "next/link"; -import { useParams } from "next/navigation"; -import { CartQuantityControl } from "@/components/CartQuantityControl"; import { useCart } from "@/app/[name]/(Dialogs)/cart/hook/useCart"; import type { Product, ProductImage } from "@/app/[name]/(Main)/types/Types"; -import { - hasVariants, - getPrimaryVariantId, - getProductEffectivePrice, -} from "@/app/[name]/(Main)/types/Types"; +import { getPrimaryVariantId, getProductEffectivePrice, hasVariants } from "@/app/[name]/(Main)/types/Types"; +import { CartQuantityControl } from "@/components/CartQuantityControl"; +import { ArrowLeft } from "iconsax-react"; +import Link from "next/link"; +import { useParams } from "next/navigation"; +import { memo, useMemo } from "react"; -export type MenuItemViewMode = 'list' | 'grid'; +export type MenuItemViewMode = "list" | "grid"; interface MenuItemProps { product: Product; @@ -25,14 +22,12 @@ interface MenuItemProps { viewMode?: MenuItemViewMode; } -const MenuItem = ({ product, variantId: variantIdProp, variantValue: variantValueProp, viewMode = 'list' }: MenuItemProps) => { +const MenuItem = ({ product, variantId: variantIdProp, variantValue: variantValueProp, viewMode = "list" }: MenuItemProps) => { const { items, addToCart, removeFromCart, isCartMutating } = useCart(); const params = useParams<{ name: string }>(); const name = params?.name || ""; const variantId = variantIdProp ?? getPrimaryVariantId(product); - const selectedVariant = variantId - ? product.variants?.find((v) => v.id === variantId) - : undefined; + const selectedVariant = variantId ? product.variants?.find((v) => v.id === variantId) : undefined; const withVariants = hasVariants(product); /** در لیست منو اگر تنوع داشت دکمه جزئیات؛ در سبد همیشه افزودن/کم کردن */ const showDetailsInsteadOfAdd = withVariants && variantIdProp == null; @@ -58,10 +53,7 @@ const MenuItem = ({ product, variantId: variantIdProp, variantValue: variantValu return fallbackImage; }, [product.image, product.images]); - const productName = useMemo( - () => product.name || product.title || 'بدون نام', - [product.name, product.title] - ); + const productName = useMemo(() => product.name || product.title || "بدون نام", [product.name, product.title]); /** فقط در سبد خرید تنوع نمایش داده شود */ const isInCart = variantIdProp != null; @@ -69,25 +61,22 @@ const MenuItem = ({ product, variantId: variantIdProp, variantValue: variantValu const productContent = useMemo(() => { const content = product.content; - if (!content) return ''; + if (!content) return ""; if (Array.isArray(content)) { - return content.filter(item => item && typeof item === 'string').join('، '); + return content.filter((item) => item && typeof item === "string").join("، "); } - return ''; + return ""; }, [product.content]); const productDescription = useMemo(() => { const desc = product.description || product.desc; - if (!desc || typeof desc !== 'string') return ''; - return desc.replace(/,/g, '،'); + if (!desc || typeof desc !== "string") return ""; + return desc.replace(/,/g, "،"); }, [product.description, product.desc]); - const effectivePrice = - selectedVariant != null - ? selectedVariant.price - : getProductEffectivePrice(product); + const effectivePrice = selectedVariant != null ? selectedVariant.price : getProductEffectivePrice(product); const finalPrice = useMemo(() => { const discount = product.discount || 0; if (discount > 0) { @@ -96,21 +85,11 @@ const MenuItem = ({ product, variantId: variantIdProp, variantValue: variantValu return effectivePrice; }, [effectivePrice, product.discount]); - const formattedPrice = useMemo( - () => (finalPrice ? finalPrice.toLocaleString("fa-IR") : "0"), - [finalPrice] - ); + const formattedPrice = useMemo(() => (finalPrice ? finalPrice.toLocaleString("fa-IR") : "0"), [finalPrice]); - const formattedOriginalPrice = useMemo( - () => - effectivePrice ? effectivePrice.toLocaleString("fa-IR") : "0", - [effectivePrice] - ); + const formattedOriginalPrice = useMemo(() => (effectivePrice ? effectivePrice.toLocaleString("fa-IR") : "0"), [effectivePrice]); - const hasDiscount = useMemo( - () => (product.discount || 0) > 0, - [product.discount] - ); + const hasDiscount = useMemo(() => (product.discount || 0) > 0, [product.discount]); const handleAddToCart = () => { if (variantId) addToCart(variantId); @@ -122,59 +101,33 @@ const MenuItem = ({ product, variantId: variantIdProp, variantValue: variantValu const productDetailUrl = `/${name}/${product.id}?category=${product.category.id}`; - if (viewMode === 'grid') { + if (viewMode === "grid") { return (
- {productName} + {productName} -
- {productName} -
- {variantValueDisplay && ( - - {variantValueDisplay} - - )} +
{productName}
+ {variantValueDisplay && {variantValueDisplay}}
{hasDiscount ? ( <> - - {formattedOriginalPrice} T - - - {formattedPrice} T - + {formattedOriginalPrice} T + {formattedPrice} T ) : ( - - {formattedPrice} T - + {formattedPrice} T )}
{showDetailsInsteadOfAdd ? ( - + جزئیات ) : ( - + )}
@@ -182,70 +135,45 @@ const MenuItem = ({ product, variantId: variantIdProp, variantValue: variantValu } return ( -
- - {productName} +
+ + {productName} -
+
-
- {productName} -
- {variantValueDisplay && ( - - {variantValueDisplay} - - )} +
{productName}
+ {variantValueDisplay && {variantValueDisplay}}
{(productContent || productDescription) && ( -
- {productContent || productDescription} -
+
{productContent || productDescription}
)}
-
-
- {hasDiscount ? ( - <> - - {formattedOriginalPrice} T - - - {formattedPrice} T - - - ) : ( - - {formattedPrice} T - - )} -
- {showDetailsInsteadOfAdd ? ( - - جزئیات - +
+ {hasDiscount ? ( + <> + {formattedOriginalPrice} T + {formattedPrice} T + ) : ( - + {formattedPrice} T )}
+
+ {showDetailsInsteadOfAdd ? ( + + جزئیات + + + ) : ( +
+ +
+ )} +
); }; diff --git a/src/components/listview/MenuItemRenderer.tsx b/src/components/listview/MenuItemRenderer.tsx index 52b0a1d..117c31d 100644 --- a/src/components/listview/MenuItemRenderer.tsx +++ b/src/components/listview/MenuItemRenderer.tsx @@ -15,7 +15,7 @@ function MenuItemRendererComponent({ children, variant = 'list', ...rest }: Prop className={`${rest.className} box-shadow-normal transition-all duration-200 ease-out w-full bg-container rounded-3xl ${ isGrid ? 'p-3 flex flex-col' - : 'py-4 pb-4! px-4 flex items-center justify-between gap-4' + : 'py-4 pb-4! px-4 flex items-stretch' }`} > {children}