diff --git a/frontend/components/cart/delivery/AddressModal.vue b/frontend/components/cart/delivery/AddressModal.vue index 35c20f4..dce9c0f 100644 --- a/frontend/components/cart/delivery/AddressModal.vue +++ b/frontend/components/cart/delivery/AddressModal.vue @@ -169,9 +169,10 @@ watch( آدرس شما؟ - * + آدرس شما؟ + * + - // import import useGetCategories from "~/composables/api/product/useGetCategories"; @@ -11,22 +10,35 @@ const { data: categories, suspense } = useGetCategories(); const search = ref(""); const debouncedSearch = refDebounced(search, 300); +const selectedCategory = ref("همه دسته ها"); + // computed +const mainCategoriesMenu = computed(() => { + const categoriesList = categories.value + ? categories.value.map((category) => category.name) + : []; + categoriesList.unshift("همه دسته ها"); + + return categoriesList; +}); + const filteredCategories = computed(() => { + if (categories.value) { + return categories.value + .flatMap((mainCategory) => mainCategory.subcategorys) + .filter((category) => { + if (selectedCategory.value === "همه دسته ها") { + return category.name.includes(debouncedSearch.value); + } - if (debouncedSearch.value.length > 0) { - return categories.value!.map((cat) => { - const copyOfCategory = { ...cat }; - copyOfCategory.subcategorys = copyOfCategory.subcategorys.filter((subcat) => { - return subcat.name.includes(debouncedSearch.value); + return ( + category.name.includes(debouncedSearch.value) && + category.parent === selectedCategory.value + ); }); - - return copyOfCategory; - }); } - - return categories.value!; + return []; }); // ssr @@ -36,78 +48,65 @@ const response = await suspense(); if (response.isError) { throw createError({ statusCode: 500, - statusMessage: `Error in categories page prefetch` + statusMessage: `Error in categories page prefetch`, }); } - - - دسته بندی ها - - - - - - - - - - - - - - - - - - {{ mainCategory.name }} - - - - - - + دسته بندی ها + + + + + - - + + + + + + + + + - + - + دسته بندی یافت نشد :(