diff --git a/src/modules/market/stores/market.ts b/src/modules/market/stores/market.ts index b1a11ba..7c0d8b1 100644 --- a/src/modules/market/stores/market.ts +++ b/src/modules/market/stores/market.ts @@ -239,14 +239,23 @@ export const useMarketStore = defineStore('market', () => { } const addProduct = (product: Product) => { - const existingIndex = products.value.findIndex(p => p.id === product.id) + // Lookup stallName from the current stall set — the value passed in by + // the caller can be stale ("Unknown Stall") if the stall event hadn't + // arrived yet. The reverse race (stall arrives first) is handled in + // addStall below. + const matchedStall = stalls.value.find(s => s.id === product.stall_id) + const enriched: Product = matchedStall + ? { ...product, stallName: matchedStall.name } + : product + + const existingIndex = products.value.findIndex(p => p.id === enriched.id) if (existingIndex >= 0) { - products.value[existingIndex] = product + products.value[existingIndex] = enriched } else { - products.value.push(product) + products.value.push(enriched) } } - + const addStall = (stall: Stall) => { const existingIndex = stalls.value.findIndex(s => s.id === stall.id) if (existingIndex >= 0) { @@ -254,6 +263,14 @@ export const useMarketStore = defineStore('market', () => { } else { stalls.value.push(stall) } + // Re-stamp stallName on any products that arrived before this stall did + // (or whose stall name has changed). Direct property mutation on items + // in a reactive array triggers Vue's deep reactivity. + products.value.forEach(p => { + if (p.stall_id === stall.id && p.stallName !== stall.name) { + p.stallName = stall.name + } + }) } const addMarket = (market: Market) => {