From 478b83ddd3f7c2b6b3d5b21011b55bc0e8b69c51 Mon Sep 17 00:00:00 2001 From: padreug Date: Fri, 26 Sep 2025 17:20:59 +0200 Subject: [PATCH] FIX BUILD ERRORS & AVOID INFINITE RECURSION: Enhance product enrichment and type definitions in MerchantStore component - Updated the product enrichment logic in MerchantStore.vue to ensure all necessary properties match the Product interface, improving data consistency. - Added optional properties for active status, pending state, and configuration in the Product interface within market.ts, enhancing flexibility for merchant store management. - Improved type assertions in MarketPage.vue and StallView.vue to ensure proper type handling for product data, enhancing type safety and clarity. These changes improve the robustness and reliability of product data handling across the market components, enhancing the overall user experience. --- .../market/components/MerchantStore.vue | 21 ++++++++++++++++--- src/modules/market/types/market.ts | 4 ++++ src/modules/market/views/MarketPage.vue | 13 +++++------- src/modules/market/views/StallView.vue | 13 +++++++----- 4 files changed, 35 insertions(+), 16 deletions(-) diff --git a/src/modules/market/components/MerchantStore.vue b/src/modules/market/components/MerchantStore.vue index 1438b73..f4ea030 100644 --- a/src/modules/market/components/MerchantStore.vue +++ b/src/modules/market/components/MerchantStore.vue @@ -516,10 +516,25 @@ const loadStallProducts = async () => { inkey, activeStall.value.id! ) - // Enrich products with stall name + // Enrich products with stall name and missing properties to match Product interface const enrichedProducts = (products || []).map(product => ({ - ...product, - stallName: activeStall.value?.name || 'Unknown Stall' + id: product.id || `${product.stall_id}-${Date.now()}`, // Ensure id is always string + stall_id: product.stall_id, + stallName: activeStall.value?.name || 'Unknown Stall', + name: product.name, + description: product.config?.description || '', + price: product.price, + currency: activeStall.value?.currency || 'sats', // Use stall currency + quantity: product.quantity, + images: product.images, + categories: product.categories, + createdAt: product.event_created_at || Date.now(), + updatedAt: Date.now(), + nostrEventId: product.event_id, + // API-specific properties that are expected by the template + active: product.active ?? true, + pending: product.pending ?? false, + config: product.config || { currency: activeStall.value?.currency || 'sats' } })) stallProducts.value = enrichedProducts diff --git a/src/modules/market/types/market.ts b/src/modules/market/types/market.ts index 3b038b0..253041e 100644 --- a/src/modules/market/types/market.ts +++ b/src/modules/market/types/market.ts @@ -40,6 +40,10 @@ export interface Product { createdAt: number updatedAt: number nostrEventId?: string + // API-specific properties for merchant store management + active?: boolean + pending?: boolean + config?: { currency?: string, [key: string]: any } } export interface Order { diff --git a/src/modules/market/views/MarketPage.vue b/src/modules/market/views/MarketPage.vue index ec29a2e..fce1d4a 100644 --- a/src/modules/market/views/MarketPage.vue +++ b/src/modules/market/views/MarketPage.vue @@ -46,7 +46,7 @@
{ return searchResults.value.length > 0 ? searchResults.value - : marketStore.products + : (marketStore.products as Product[]) }) // Category filtering with optimized composable const { allCategories, - filteredProducts: categoryFilteredProducts, selectedCount: selectedCategoriesCount, selectedCategoryNames: selectedCategories, hasActiveFilters, filterMode, toggleCategory, clearAllCategories: clearAllCategoryFilters, - setFilterMode, - toggleFilterMode, - categoryStats + setFilterMode } = useCategoryFilter(productsForCategoryFilter) let unsubscribe: (() => void) | null = null diff --git a/src/modules/market/views/StallView.vue b/src/modules/market/views/StallView.vue index bf73c17..6a771f3 100644 --- a/src/modules/market/views/StallView.vue +++ b/src/modules/market/views/StallView.vue @@ -138,7 +138,7 @@ @@ -159,9 +159,8 @@ import { ref, computed, onMounted, watch } from 'vue' import { useRoute, useRouter } from 'vue-router' import { useMarketStore } from '@/modules/market/stores/market' -import { Card, CardContent } from '@/components/ui/card' +import { Card } from '@/components/ui/card' import { Button } from '@/components/ui/button' -import { Input } from '@/components/ui/input' import { Badge } from '@/components/ui/badge' import { Select, @@ -184,6 +183,7 @@ const marketStore = useMarketStore() // State const isLoading = ref(false) const searchResults = ref([]) +const searchQuery = ref('') const sortBy = ref('name') const selectedCategories = ref([]) const showProductDetail = ref(false) @@ -213,8 +213,8 @@ const searchOptions: FuzzySearchOptions = { const stallId = computed(() => route.params.stallId as string) // Get stall data -const stall = computed(() => { - return marketStore.stalls.find(s => s.id === stallId.value) +const stall = computed(() => { + return marketStore.stalls.find(s => s.id === stallId.value) as Stall | undefined }) // Get products for this stall @@ -284,11 +284,14 @@ const toggleCategoryFilter = (category: string) => { const clearFilters = () => { selectedCategories.value = [] searchResults.value = [] + searchQuery.value = '' } // Handle fuzzy search results const handleSearchResults = (results: Product[]) => { searchResults.value = results + // Extract search query from fuzzy search component if needed + // For now, we'll track it separately } const viewProductDetails = (product: Product) => {