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,
|
inkey,
|
||||||
activeStall.value.id!
|
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) {
|
} catch (error) {
|
||||||
console.error('Failed to load products:', error)
|
console.error('Failed to load products:', error)
|
||||||
stallProducts.value = []
|
stallProducts.value = []
|
||||||
|
|
|
||||||
|
|
@ -289,10 +289,16 @@ export function useMarket() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const productData = JSON.parse(latestEvent.content)
|
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 = {
|
const product = {
|
||||||
id: productId,
|
id: productId,
|
||||||
stall_id: productData.stall_id || 'unknown',
|
stall_id: stallId,
|
||||||
stallName: productData.stallName || 'Unknown Stall',
|
stallName: stallName,
|
||||||
name: productData.name || 'Unnamed Product',
|
name: productData.name || 'Unnamed Product',
|
||||||
description: productData.description || '',
|
description: productData.description || '',
|
||||||
price: productData.price || 0,
|
price: productData.price || 0,
|
||||||
|
|
@ -468,10 +474,16 @@ export function useMarket() {
|
||||||
const productId = event.tags.find((tag: any) => tag[0] === 'd')?.[1]
|
const productId = event.tags.find((tag: any) => tag[0] === 'd')?.[1]
|
||||||
if (productId) {
|
if (productId) {
|
||||||
const productData = JSON.parse(event.content)
|
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 = {
|
const product = {
|
||||||
id: productId,
|
id: productId,
|
||||||
stall_id: productData.stall_id || 'unknown',
|
stall_id: stallId,
|
||||||
stallName: productData.stallName || 'Unknown Stall',
|
stallName: stallName,
|
||||||
pubkey: event.pubkey,
|
pubkey: event.pubkey,
|
||||||
name: productData.name || 'Unnamed Product',
|
name: productData.name || 'Unnamed Product',
|
||||||
description: productData.description || '',
|
description: productData.description || '',
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue