feat: Add MarketTest page and enhance error handling in market components

- Introduce MarketTest.vue for testing market loading and state management.
- Update error handling in Market.vue and useMarket composable to utilize marketStore for consistent error reporting.
- Enhance logging throughout market loading processes for better debugging and user feedback.
This commit is contained in:
padreug 2025-08-02 18:03:25 +02:00
parent 1a3510becb
commit 1ed8759162
6 changed files with 144 additions and 10 deletions

View file

@ -17,7 +17,6 @@ export function useMarket() {
const marketStore = useMarketStore()
const isLoading = ref(false)
const error = ref<string | null>(null)
const isConnected = ref(false)
// Market loading state
@ -25,7 +24,7 @@ export function useMarket() {
try {
isLoading.value = true
marketStore.setLoading(true)
error.value = null
marketStore.setError(null)
console.log('Loading market with naddr:', naddr)
@ -37,12 +36,14 @@ export function useMarket() {
throw new Error('Invalid market naddr')
}
console.log('About to load market data...')
// Load market data from Nostr
await loadMarketData(data)
console.log('Market data loaded successfully')
} catch (err) {
console.error('Error loading market:', err)
error.value = err instanceof Error ? err.message : 'Failed to load market'
marketStore.setError(err instanceof Error ? err.message : 'Failed to load market')
// Don't throw error, let the UI handle it gracefully
} finally {
isLoading.value = false
@ -52,20 +53,35 @@ export function useMarket() {
const loadMarketData = async (marketData: any) => {
try {
console.log('Starting loadMarketData...')
// Get Nostr client
const client = nostrStore.getClient()
console.log('Got Nostr client')
// Load market configuration
console.log('Loading market config...')
await loadMarketConfig(marketData)
console.log('Market config loaded')
// Load stalls for this market
console.log('Loading stalls...')
await loadStalls(marketData.pubkey)
console.log('Stalls loaded')
// Load products for all stalls
console.log('Loading products...')
await loadProducts()
console.log('Products loaded')
// Subscribe to real-time updates
subscribeToMarketUpdates()
console.log('Subscribing to updates...')
try {
subscribeToMarketUpdates()
console.log('Subscribed to updates')
} catch (err) {
console.warn('Failed to subscribe to updates:', err)
// Don't fail the entire load process if subscription fails
}
} catch (err) {
console.error('Error loading market data:', err)
@ -113,7 +129,8 @@ export function useMarket() {
opts: {
name: 'Default Market',
description: 'A default market',
merchants: []
merchants: [],
ui: {}
}
}
@ -132,7 +149,8 @@ export function useMarket() {
opts: {
name: 'Default Market',
description: 'A default market',
merchants: []
merchants: [],
ui: {}
}
}
@ -340,6 +358,8 @@ export function useMarket() {
} catch (err) {
console.error('Error subscribing to market updates:', err)
// Return a no-op function if subscription fails
return () => {}
}
}
@ -462,11 +482,17 @@ export function useMarket() {
const connectToMarket = async () => {
try {
console.log('Checking Nostr connection...')
console.log('Current connection state:', nostrStore.isConnected)
if (!nostrStore.isConnected) {
console.log('Connecting to Nostr relays...')
await nostrStore.connect()
console.log('Connected to Nostr relays')
}
isConnected.value = nostrStore.isConnected
console.log('Final connection state:', isConnected.value)
if (!isConnected.value) {
throw new Error('Failed to connect to Nostr relays')
@ -486,7 +512,6 @@ export function useMarket() {
return {
// State
isLoading: readonly(isLoading),
error: readonly(error),
isConnected: readonly(isConnected),
// Actions