diff --git a/src/app/[name]/(Main)/components/CategoryScroll.tsx b/src/app/[name]/(Main)/components/CategoryScroll.tsx
index 548fb73..48e9624 100644
--- a/src/app/[name]/(Main)/components/CategoryScroll.tsx
+++ b/src/app/[name]/(Main)/components/CategoryScroll.tsx
@@ -42,52 +42,69 @@ const CategoryScroll = ({
className,
}: Props) => {
const { renderer: Renderer, imageSize } = variantConfig[variant];
+ const selectedParent =
+ categories.find((c) => c.id === selectedCategory) ??
+ categories.find((c) => c.children?.some((ch) => ch.id === selectedCategory));
+ const children = selectedParent?.children ?? [];
const handleSelect = (categoryId: string) => () => onSelect(categoryId);
return (
-
- {/*
+
-
- همه
- */}
- {categories.map((item) => {
- const isSelected = item.id === selectedCategory;
+ {categories.map((item) => {
+ const isSelected =
+ item.id === selectedCategory ||
+ item.children?.some((ch) => ch.id === selectedCategory);
- return (
-
-
- {item.title}
-
- );
- })}
-
+ return (
+
+
+ {item.title}
+
+ );
+ })}
+
+
+ {children.length > 0 && (
+
+ {children.map((child) => {
+ const isChildSelected = child.id === selectedCategory;
+
+ return (
+
+ {child.title}
+
+ );
+ })}
+
+ )}
+
);
};
diff --git a/src/app/[name]/(Main)/page.tsx b/src/app/[name]/(Main)/page.tsx
index 6724bd1..d612f14 100644
--- a/src/app/[name]/(Main)/page.tsx
+++ b/src/app/[name]/(Main)/page.tsx
@@ -109,8 +109,20 @@ const MenuIndex = () => {
const lowerFilterQuery = filterSearch ? filterSearch.toLowerCase() : "";
const selectedCatId = selectedCategory === '0' ? null : selectedCategory;
+ // اگر دستهٔ اصلی انتخاب شده، خودش + همهٔ زیردستهها را در نظر بگیر تا غذاهای زیردسته هم بیایند
+ const effectiveCategoryIds = (() => {
+ if (!selectedCatId) return null;
+ const parent = categories.find((c) => c.id === selectedCatId);
+ if (parent?.children?.length) {
+ return new Set([parent.id, ...parent.children.map((ch) => ch.id)]);
+ }
+ return new Set([selectedCatId]);
+ })();
+
const filtered = products.filter((item) => {
- const matchesCategory = !selectedCatId || item.category?.id === selectedCatId;
+ const matchesCategory =
+ !selectedCatId ||
+ (item.category?.id != null && effectiveCategoryIds?.has(item.category.id));
const itemName = item.name ?? item.title;
const matchesSearch =
!search || itemName.toLowerCase().includes(lowerSearch);
@@ -149,7 +161,7 @@ const MenuIndex = () => {
return 0;
}
});
- }, [selectedCategory, search, filterSearch, products, sorting]);
+ }, [selectedCategory, search, filterSearch, products, sorting, categories]);
if (isLoading) {
return ;
diff --git a/src/app/[name]/(Main)/types/Types.ts b/src/app/[name]/(Main)/types/Types.ts
index 2959d04..58a1016 100644
--- a/src/app/[name]/(Main)/types/Types.ts
+++ b/src/app/[name]/(Main)/types/Types.ts
@@ -10,10 +10,13 @@ export interface Category {
createdAt: string;
updatedAt: string;
deletedAt: string | null;
+ parent: string | null;
title: string;
isActive: boolean;
- restaurant: string;
+ shop: string;
avatarUrl: string | null;
+ order: number | null;
+ children: Category[];
}
export type CategoriesResponse = BaseResponse;
diff --git a/src/components/listview/CategorySmallItemRenderer.tsx b/src/components/listview/CategorySmallItemRenderer.tsx
index 4e5d823..afe9a51 100644
--- a/src/components/listview/CategorySmallItemRenderer.tsx
+++ b/src/components/listview/CategorySmallItemRenderer.tsx
@@ -11,7 +11,7 @@ function CategorySmallItemRenderer({ children, ...rest }: Props) {