From 56bcb8ec04d958141293800edde25a47927ee8d9 Mon Sep 17 00:00:00 2001 From: padreug Date: Fri, 26 Sep 2025 23:56:37 +0200 Subject: [PATCH] refactor: update ProductCard, ProductGrid, and MarketPage components for improved product handling and internal state management - Removed direct store dependency from ProductCard.vue, replacing it with event emission for adding products to the cart. - Enhanced ProductGrid.vue to manage product detail dialog internally, improving user interaction and state handling. - Streamlined MarketPage.vue by removing redundant product detail dialog logic, focusing on cleaner component structure. - Updated event handling for adding products to the cart with quantity support, enhancing flexibility in product management. These changes improve the modularity and maintainability of the market components, providing a better user experience when interacting with products. --- src/modules/market/components/ProductCard.vue | 13 +++-- src/modules/market/components/ProductGrid.vue | 49 ++++++++++++++++--- src/modules/market/views/MarketPage.vue | 31 +----------- src/modules/market/views/StallView.vue | 28 ++--------- 4 files changed, 53 insertions(+), 68 deletions(-) diff --git a/src/modules/market/components/ProductCard.vue b/src/modules/market/components/ProductCard.vue index 532c074..21ef2a0 100644 --- a/src/modules/market/components/ProductCard.vue +++ b/src/modules/market/components/ProductCard.vue @@ -101,7 +101,6 @@ \ No newline at end of file diff --git a/src/modules/market/views/MarketPage.vue b/src/modules/market/views/MarketPage.vue index fa86a8f..82de5cb 100644 --- a/src/modules/market/views/MarketPage.vue +++ b/src/modules/market/views/MarketPage.vue @@ -78,7 +78,6 @@ empty-title="No products found" empty-message="Try adjusting your search or filters" @add-to-cart="addToCart" - @view-details="viewProduct" @view-stall="viewStall" /> @@ -91,14 +90,6 @@ - - @@ -116,7 +107,6 @@ import { ShoppingCart } from 'lucide-vue-next' import MarketFuzzySearch from '../components/MarketFuzzySearch.vue' import ProductGrid from '../components/ProductGrid.vue' import CategoryFilterBar from '../components/CategoryFilterBar.vue' -import ProductDetailDialog from '../components/ProductDetailDialog.vue' import type { Product } from '../types/market' import type { FuzzySearchOptions } from '@/composables/useFuzzySearch' @@ -149,9 +139,6 @@ let unsubscribe: (() => void) | null = null // Fuzzy search state const searchResults = ref([]) -// Product detail dialog state -const showProductDetail = ref(false) -const selectedProduct = ref(null) // Fuzzy search configuration for products and stalls const searchOptions: FuzzySearchOptions = { @@ -252,24 +239,10 @@ const retryLoadMarket = () => { loadMarket() } -const addToCart = (product: any) => { - marketStore.addToCart(product) +const addToCart = (product: Product, quantity?: number) => { + marketStore.addToStallCart(product, quantity || 1) } -const viewProduct = (product: Product) => { - selectedProduct.value = product - showProductDetail.value = true -} - -const closeProductDetail = () => { - showProductDetail.value = false - selectedProduct.value = null -} - -const handleAddToCart = (product: Product, quantity: number) => { - marketStore.addToCart({ ...product, quantity }) - closeProductDetail() -} const viewStall = (stallId: string) => { // Navigate to the stall view page diff --git a/src/modules/market/views/StallView.vue b/src/modules/market/views/StallView.vue index 5b18df3..e557d14 100644 --- a/src/modules/market/views/StallView.vue +++ b/src/modules/market/views/StallView.vue @@ -126,18 +126,10 @@ :empty-message="searchQuery || selectedCategories.length > 0 ? 'Try adjusting your filters or search terms' : 'This stall doesn\'t have any products yet'" - @view-details="viewProductDetails" @view-stall="viewStall" - /> - - - + @@ -158,7 +150,6 @@ import { import { ArrowLeft, Store, X } from 'lucide-vue-next' import FuzzySearch from '@/components/ui/fuzzy-search/FuzzySearch.vue' import ProductGrid from '../components/ProductGrid.vue' -import ProductDetailDialog from '../components/ProductDetailDialog.vue' import type { Product, Stall } from '../types/market' import type { FuzzySearchOptions } from '@/composables/useFuzzySearch' @@ -172,8 +163,6 @@ const searchResults = ref([]) const searchQuery = ref('') const sortBy = ref('name') const selectedCategories = ref([]) -const showProductDetail = ref(false) -const selectedProduct = ref(null) const logoError = ref(false) // Fuzzy search configuration for stall products @@ -280,20 +269,10 @@ const handleSearchResults = (results: Product[]) => { // For now, we'll track it separately } -const viewProductDetails = (product: Product) => { - selectedProduct.value = product - showProductDetail.value = true +const handleAddToCart = (product: Product, quantity?: number) => { + marketStore.addToStallCart(product, quantity || 1) } -const closeProductDetail = () => { - showProductDetail.value = false - selectedProduct.value = null -} - -const handleAddToCart = (product: Product, quantity: number) => { - marketStore.addToStallCart(product, quantity) - closeProductDetail() -} const viewStall = (otherStallId: string) => { if (otherStallId !== stallId.value) { @@ -322,7 +301,6 @@ watch(() => route.params.stallId, (newStallId) => { if (newStallId && newStallId !== stallId.value) { // Reset filters when navigating to a different stall clearFilters() - closeProductDetail() } })