diff --git a/src/app/[name]/(Main)/[id]/page.tsx b/src/app/[name]/(Main)/[id]/page.tsx
index b7755fd..4623160 100644
--- a/src/app/[name]/(Main)/[id]/page.tsx
+++ b/src/app/[name]/(Main)/[id]/page.tsx
@@ -19,7 +19,7 @@ type Props = object
function FoodPage({ }: Props) {
- const { id } = useParams();
+ const { id, name } = useParams();
const router = useRouter();
const { isSuccess } = useGetProfile();
const { data: food, isLoading } = useGetFood(id as string);
@@ -116,6 +116,16 @@ function FoodPage({ }: Props) {
? foodData.content.join('، ')
: foodData.content || foodData.desc || '';
+ const handleBackToMenu = () => {
+ const urlParams = new URLSearchParams(window.location.search);
+ const categoryParam = urlParams.get('category') || foodData.category?.id;
+ if (categoryParam) {
+ router.push(`/${name}?category=${categoryParam}`);
+ } else {
+ router.push(`/${name}`);
+ }
+ };
+
return (
@@ -132,7 +142,7 @@ function FoodPage({ }: Props) {
{categoryName || '-'}
-
diff --git a/src/app/[name]/(Main)/components/CategoryScroll.tsx b/src/app/[name]/(Main)/components/CategoryScroll.tsx
index f25fd66..548fb73 100644
--- a/src/app/[name]/(Main)/components/CategoryScroll.tsx
+++ b/src/app/[name]/(Main)/components/CategoryScroll.tsx
@@ -29,7 +29,7 @@ const variantConfig: Record<
type Props = {
categories: Category[];
selectedCategory: string;
- onSelect: (index: number) => void;
+ onSelect: (categoryId: string) => void;
variant?: Variant;
className?: string;
};
@@ -43,7 +43,7 @@ const CategoryScroll = ({
}: Props) => {
const { renderer: Renderer, imageSize } = variantConfig[variant];
- const handleSelect = (index: number) => () => onSelect(index);
+ const handleSelect = (categoryId: string) => () => onSelect(categoryId);
return (
همه
*/}
- {categories.map((item, index) => {
- const categoryIndex = index;
- const isSelected = String(categoryIndex) === selectedCategory;
+ {categories.map((item) => {
+ const isSelected = item.id === selectedCategory;
return (
{
useEffect(() => {
if (isInitialMount) {
setSearch(null);
- setSelectedCategory(null);
+ // category را نگه میداریم تا در بک زدن حفظ شود
+ // setSelectedCategory(null);
setSelectedIngredients(null);
setSelectedDeliveryId(null);
setSorting(null);
setIsInitialMount(false);
}
- }, [isInitialMount, setSearch, setSelectedCategory, setSelectedIngredients, setSelectedDeliveryId, setSorting]);
+ }, [isInitialMount, setSearch, setSelectedIngredients, setSelectedDeliveryId, setSorting]);
const onScroll = useCallback(() => {
if (!wrapperRef?.current?.parentElement?.parentElement?.scrollTop || !smallCategoriesRef.current?.offsetTop) return;
@@ -80,8 +81,8 @@ const MenuIndex = () => {
setSearch(e.target.value);
}, [setSearch]);
- const updateCategory = useCallback((index: number) => {
- setSelectedCategory(String(index));
+ const updateCategory = useCallback((categoryId: string) => {
+ setSelectedCategory(categoryId);
}, [setSelectedCategory]);
const sortingIndex = Number(sorting);
@@ -106,10 +107,10 @@ const MenuIndex = () => {
if (!foods.length) return [];
const lowerSearch = search.toLowerCase();
const lowerIngredients = selectedIngredients ? selectedIngredients.toLowerCase() : "";
- const selectedCatId = categories[+selectedCategory]?.id;
+ const selectedCatId = selectedCategory === '0' ? null : selectedCategory;
const filtered = foods.filter((item) => {
- const matchesCategory = item.category?.id === selectedCatId;
+ const matchesCategory = !selectedCatId || item.category?.id === selectedCatId;
const itemName = item.name || item.title || item.foodName || "";
const matchesSearch =
!search || itemName.toLowerCase().includes(lowerSearch);
@@ -150,7 +151,7 @@ const MenuIndex = () => {
return 0;
}
});
- }, [selectedCategory, search, selectedIngredients, selectedDeliveryId, foods, categories, sorting]);
+ }, [selectedCategory, search, selectedIngredients, selectedDeliveryId, foods, sorting]);
if (isLoading) {
return ;
@@ -170,7 +171,7 @@ const MenuIndex = () => {
- {categories[+selectedCategory]?.title || ''}
+ {selectedCategory === '0' ? '' : categories.find(c => c.id === selectedCategory)?.title || ''}
diff --git a/src/components/listview/MenuItem.tsx b/src/components/listview/MenuItem.tsx
index f5d6f12..6dcb19d 100644
--- a/src/components/listview/MenuItem.tsx
+++ b/src/components/listview/MenuItem.tsx
@@ -93,7 +93,7 @@ const MenuItem = ({ food }: MenuItemProps) => {
removeFromCart(food.id);
};
- const foodDetailUrl = `/${name}/${food.id}`;
+ const foodDetailUrl = `/${name}/${food.id}?category=${food.category.id}`;
return (