diff --git a/static/components/customer-orders/customer-orders.html b/static/components/customer-orders/customer-orders.html
index 18642f8..285dbc6 100644
--- a/static/components/customer-orders/customer-orders.html
+++ b/static/components/customer-orders/customer-orders.html
@@ -1,10 +1,12 @@
-
+
No products in cart!
-
+
+
+
@@ -19,11 +21,11 @@
- Todo: stall name
+ Todo: merchant name
- By
+ By
@@ -37,26 +39,37 @@
-
+
+
-
-
- products
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+ xxxx
+
+
+
+
+
diff --git a/static/components/customer-orders/customer-orders.js b/static/components/customer-orders/customer-orders.js
index 2951a43..788d828 100644
--- a/static/components/customer-orders/customer-orders.js
+++ b/static/components/customer-orders/customer-orders.js
@@ -5,16 +5,32 @@ async function customerOrders(path) {
name: 'orders',
template,
- props: ['orders'],
+ props: ['orders', 'products', 'stalls'],
data: function () {
return {}
},
- computed: {},
- methods: {
-
+ computed: {
+ merchantOrders: function () {
+ return Object.keys(this.orders).map(pubkey => ({ pubkey, orders: this.orders[pubkey] }))
+ }
},
- created() {
+ methods: {
+ stallNameForOrder: function (order) {
+ console.log('### stallNameForOrder', order)
+ const productId = order.items[0]?.product_id
+ if (!productId) return 'Stall Name'
+ const product = this.products.find(p => p.id === productId)
+ if (!product) return 'Stall Name'
+ const stall = this.stalls.find(s => s.id === product.stall_id)
+ if (!stall) return 'Stall Name'
+ return stall.name
+ }
+
+ },
+ created() {
console.log('### orders', this.orders)
+ console.log('### products', this.products)
+ console.log('### stall', this.stalls)
}
})
}
diff --git a/static/js/market.js b/static/js/market.js
index c88fe4a..4bc39c9 100644
--- a/static/js/market.js
+++ b/static/js/market.js
@@ -76,6 +76,8 @@ const market = async () => {
events: [],
stalls: [],
products: [],
+ orders: {},
+
profiles: new Map(),
searchText: null,
inputPubkey: null,
@@ -102,14 +104,38 @@ const market = async () => {
}
},
computed: {
- allOrders() {
- const prefix = 'nostrmarket.orders.'
- const orderKeys = this.$q.localStorage.getAllKeys().filter(k => k.startsWith(prefix))
+ // allOrders() {
+ // console.log('### allOrders compute')
+ // const prefix = 'nostrmarket.orders.'
- return orderKeys.map((key) => ({
- pubkey: key.substring(prefix.length),
- orders: this.$q.localStorage.getItem(key)
- }), {})
+ // return Object.keys(this.orders).map((key) => ({
+ // pubkey: key.substring(prefix.length),
+ // orders: this.orders[key]
+ // }), {})
+ // },
+ orderedProducts: function () {
+ const allItems = Object.keys(this.orders)
+ .map(pubkey => this.orders[pubkey]
+ .map(o => o.items)
+ .flat()
+ .map(i => i.product_id)
+ .flat())
+ .flat()
+ const uniqueProductIds = [...new Set(allItems)];
+ return this.products.filter(p => uniqueProductIds.indexOf(p.id) !== -1)
+ },
+ orderedStalls: function () {
+ const allItems = Object.keys(this.orders)
+ .map(pubkey => this.orders[pubkey]
+ .map(o => o.items)
+ .flat()
+ .map(i => i.product_id)
+ .flat())
+ .flat()
+ const uniqueProductIds = [...new Set(allItems)];
+ const uniqueStallIds = this.products.filter(p => uniqueProductIds.indexOf(p.id) !== -1).map(p => p.stall_id)
+
+ return this.stalls.filter(s => uniqueStallIds.indexOf(s.id) !== -1)
},
filterProducts() {
let products = this.products
@@ -160,6 +186,14 @@ const market = async () => {
this.account = this.$q.localStorage.getItem('nostrmarket.account') || null
+ const prefix = 'nostrmarket.orders.'
+ const orderKeys = this.$q.localStorage.getAllKeys().filter(k => k.startsWith(prefix))
+ orderKeys.forEach(k => {
+ const pubkey = k.substring(prefix.length)
+ this.orders[pubkey] = this.$q.localStorage.getItem(k)
+ })
+
+
//console.log("UUID", crypto.randomUUID())
@@ -405,6 +439,7 @@ const market = async () => {
return obj
})
.filter(f => f)
+ console.log('### products', this.products)
},
async initNostr() {
this.$q.loading.show()
@@ -796,10 +831,11 @@ const market = async () => {
persistOrderUpdate(pubkey, orderUpdate) {
console.log('### persistOrderUpdate', pubkey, orderUpdate)
- const orders = this.$q.localStorage.getItem(`nostrmarket.orders.${pubkey}`) || []
+ let orders = this.$q.localStorage.getItem(`nostrmarket.orders.${pubkey}`) || []
let order = orders.find(o => o.id === orderUpdate.id)
if (!order) {
- orders.push({ ...orderUpdate, messages: orderUpdate.message ? [orderUpdate.message] : [] })
+ orders.unshift({ ...orderUpdate, messages: orderUpdate.message ? [orderUpdate.message] : [] })
+ this.orders[pubkey] = orders
this.$q.localStorage.set(`nostrmarket.orders.${pubkey}`, orders)
return
}
@@ -815,7 +851,10 @@ const market = async () => {
order.shipped = orderUpdate.shipped
}
- this.$q.localStorage.set(`nostrmarket.orders.${pubkey}`, [order].concat(orders.filter(o => o.id !== order.id)))
+
+ orders = [order].concat(orders.filter(o => o.id !== order.id))
+ this.orders[pubkey] = orders
+ this.$q.localStorage.set(`nostrmarket.orders.${pubkey}`, orders)
}
}
diff --git a/templates/nostrmarket/market.html b/templates/nostrmarket/market.html
index 9d37351..96d0593 100644
--- a/templates/nostrmarket/market.html
+++ b/templates/nostrmarket/market.html
@@ -218,7 +218,8 @@
-
+