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.
This commit is contained in:
parent
3f47d2ff26
commit
56bcb8ec04
4 changed files with 53 additions and 68 deletions
|
|
@ -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"
|
||||
/>
|
||||
|
||||
<!-- Product Detail Dialog -->
|
||||
<ProductDetailDialog
|
||||
v-if="selectedProduct"
|
||||
:product="selectedProduct"
|
||||
:isOpen="showProductDetail"
|
||||
@close="closeProductDetail"
|
||||
@add-to-cart="handleAddToCart"
|
||||
/>
|
||||
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
|
@ -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<Product[]>([])
|
|||
const searchQuery = ref('')
|
||||
const sortBy = ref('name')
|
||||
const selectedCategories = ref<string[]>([])
|
||||
const showProductDetail = ref(false)
|
||||
const selectedProduct = ref<Product | null>(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()
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue