From 526caa2689b65d439fd11015cd64f64c61f0184e Mon Sep 17 00:00:00 2001 From: padreug Date: Thu, 25 Sep 2025 23:19:58 +0200 Subject: [PATCH] Enhance category filtering in MarketPage and market store - Added a new function `clearCategoryFilters` in the market store to reset selected category filters. - Updated MarketPage to include an enhanced category filter UI with a clear all button, active filters summary, and improved badge styling for selected categories. - Introduced computed properties for tracking selected categories and their count, improving user experience in managing filters. These changes provide a more intuitive and user-friendly interface for category filtering in the market module. --- src/modules/market/stores/market.ts | 5 ++ src/modules/market/views/MarketPage.vue | 97 ++++++++++++++++++++++--- 2 files changed, 93 insertions(+), 9 deletions(-) diff --git a/src/modules/market/stores/market.ts b/src/modules/market/stores/market.ts index a5a2cee..20c89f5 100644 --- a/src/modules/market/stores/market.ts +++ b/src/modules/market/stores/market.ts @@ -803,6 +803,10 @@ export const useMarketStore = defineStore('market', () => { filterData.value.categories.push(category) } } + + const clearCategoryFilters = () => { + filterData.value.categories = [] + } const updateSortOptions = (field: string, order: 'asc' | 'desc' = 'asc') => { sortOptions.value = { field, order } @@ -881,6 +885,7 @@ export const useMarketStore = defineStore('market', () => { updateFilterData, clearFilters, toggleCategoryFilter, + clearCategoryFilters, updateSortOptions, formatPrice, addToStallCart, diff --git a/src/modules/market/views/MarketPage.vue b/src/modules/market/views/MarketPage.vue index 564642b..ffe9dd7 100644 --- a/src/modules/market/views/MarketPage.vue +++ b/src/modules/market/views/MarketPage.vue @@ -52,19 +52,84 @@ - +
-
- +

Browse by Category

+ +
+ +
+
- {{ category.category }} - ({{ category.count }}) - + +
+ {{ category.category }} +
+ {{ category.count }} +
+
+
+ + +
+ +
+
+
+ + +
+
+
+ + + Active Filters: + +
+ + {{ category }} + +
+
+
+ {{ productsToDisplay.length }} products found +
+
@@ -107,7 +172,7 @@ import { config } from '@/lib/config' import { Button } from '@/components/ui/button' import { Badge } from '@/components/ui/badge' import { Avatar, AvatarImage, AvatarFallback } from '@/components/ui/avatar' -import { ShoppingCart } from 'lucide-vue-next' +import { ShoppingCart, X, Check, Filter } from 'lucide-vue-next' import MarketFuzzySearch from '../components/MarketFuzzySearch.vue' import ProductCard from '../components/ProductCard.vue' import type { Product } from '../types/market' @@ -232,6 +297,20 @@ const handleCategoryFilter = (category: string) => { marketStore.toggleCategoryFilter(category) } +// Computed properties for enhanced category filtering +const selectedCategoriesCount = computed(() => { + return marketStore.filterData.categories.length +}) + +const selectedCategories = computed(() => { + return marketStore.filterData.categories +}) + +// Clear all category filters +const clearAllCategoryFilters = () => { + marketStore.clearCategoryFilters() +} + onMounted(() => { // Only load market if it hasn't been preloaded if (needsToLoadMarket.value) {