Enhance product handling in MerchantStore and useMarket
- Enriched products with stall names in MerchantStore, ensuring each product displays the associated stall name or 'Unknown Stall' if not available. - Updated product addition logic in useMarket to include stall names, improving clarity and consistency across the application. - Enhanced error handling for product loading to maintain robust functionality. These changes improve the user experience by providing clearer product information in the market interface.
This commit is contained in:
parent
2e12315a35
commit
f2080abce5
2 changed files with 30 additions and 8 deletions
|
|
@ -516,7 +516,17 @@ const loadStallProducts = async () => {
|
|||
inkey,
|
||||
activeStall.value.id!
|
||||
)
|
||||
stallProducts.value = products || []
|
||||
// Enrich products with stall name
|
||||
const enrichedProducts = (products || []).map(product => ({
|
||||
...product,
|
||||
stallName: activeStall.value?.name || 'Unknown Stall'
|
||||
}))
|
||||
stallProducts.value = enrichedProducts
|
||||
|
||||
// Also add them to the market store so they appear in the main market
|
||||
enrichedProducts.forEach(product => {
|
||||
marketStore.addProduct(product)
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('Failed to load products:', error)
|
||||
stallProducts.value = []
|
||||
|
|
|
|||
|
|
@ -286,13 +286,19 @@ export function useMarket() {
|
|||
productGroups.forEach((productEvents, productId) => {
|
||||
// Sort by created_at and take the most recent
|
||||
const latestEvent = productEvents.sort((a: any, b: any) => b.created_at - a.created_at)[0]
|
||||
|
||||
|
||||
try {
|
||||
const productData = JSON.parse(latestEvent.content)
|
||||
const stallId = productData.stall_id || 'unknown'
|
||||
|
||||
// Look up the stall name from the stalls array
|
||||
const stall = marketStore.stalls.find(s => s.id === stallId)
|
||||
const stallName = stall?.name || 'Unknown Stall'
|
||||
|
||||
const product = {
|
||||
id: productId,
|
||||
stall_id: productData.stall_id || 'unknown',
|
||||
stallName: productData.stallName || 'Unknown Stall',
|
||||
stall_id: stallId,
|
||||
stallName: stallName,
|
||||
name: productData.name || 'Unnamed Product',
|
||||
description: productData.description || '',
|
||||
price: productData.price || 0,
|
||||
|
|
@ -303,7 +309,7 @@ export function useMarket() {
|
|||
createdAt: latestEvent.created_at,
|
||||
updatedAt: latestEvent.created_at
|
||||
}
|
||||
|
||||
|
||||
marketStore.addProduct(product)
|
||||
} catch (err) {
|
||||
// Silently handle parse errors
|
||||
|
|
@ -468,10 +474,16 @@ export function useMarket() {
|
|||
const productId = event.tags.find((tag: any) => tag[0] === 'd')?.[1]
|
||||
if (productId) {
|
||||
const productData = JSON.parse(event.content)
|
||||
const stallId = productData.stall_id || 'unknown'
|
||||
|
||||
// Look up the stall name from the stalls array
|
||||
const stall = marketStore.stalls.find(s => s.id === stallId)
|
||||
const stallName = stall?.name || 'Unknown Stall'
|
||||
|
||||
const product = {
|
||||
id: productId,
|
||||
stall_id: productData.stall_id || 'unknown',
|
||||
stallName: productData.stallName || 'Unknown Stall',
|
||||
stall_id: stallId,
|
||||
stallName: stallName,
|
||||
pubkey: event.pubkey,
|
||||
name: productData.name || 'Unnamed Product',
|
||||
description: productData.description || '',
|
||||
|
|
@ -483,7 +495,7 @@ export function useMarket() {
|
|||
createdAt: event.created_at,
|
||||
updatedAt: event.created_at
|
||||
}
|
||||
|
||||
|
||||
marketStore.addProduct(product)
|
||||
}
|
||||
} catch (err) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue