From 483fcedfd90e5484c9cab926087046b44797c0ec Mon Sep 17 00:00:00 2001 From: Vlad Stan Date: Thu, 6 Jul 2023 18:00:57 +0300 Subject: [PATCH] feat: remove from card --- .../components/shopping-cart-list/shopping-cart-list.js | 5 +++-- static/js/market.js | 8 ++++++++ templates/nostrmarket/market.html | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/static/components/shopping-cart-list/shopping-cart-list.js b/static/components/shopping-cart-list/shopping-cart-list.js index b9024bc..b49193b 100644 --- a/static/components/shopping-cart-list/shopping-cart-list.js +++ b/static/components/shopping-cart-list/shopping-cart-list.js @@ -5,17 +5,18 @@ async function shoppingCartList(path) { name: 'shopping-cart-list', template, - props: ['carts', 'products'], + props: ['carts'], data: function () { return {} }, computed: {}, methods: { - formatCurrency: function(value, unit){ + formatCurrency: function (value, unit) { return formatCurrency(value, unit) }, removeProduct: function (stallId, productId) { console.log('### stallId, productId', stallId, productId) + this.$emit('remove-from-cart', { stallId, productId }) } }, created() { } diff --git a/static/js/market.js b/static/js/market.js index 50dba40..321b757 100644 --- a/static/js/market.js +++ b/static/js/market.js @@ -588,6 +588,14 @@ const market = async () => { this.$q.localStorage.set('nostrmarket.shoppingCarts', this.shoppingCarts) console.log('### this.shoppingCarts', this.shoppingCarts) + }, + + removeProductFromCart(item) { + const stallCart = this.shoppingCarts.find(c => c.id === item.stallId) + if (stallCart) { + stallCart.products = stallCart.products.filter(p => p.id !== item.productId) + this.$q.localStorage.set('nostrmarket.shoppingCarts', this.shoppingCarts) + } } } diff --git a/templates/nostrmarket/market.html b/templates/nostrmarket/market.html index 102bb96..c7049fc 100644 --- a/templates/nostrmarket/market.html +++ b/templates/nostrmarket/market.html @@ -205,7 +205,7 @@ + @remove-from-cart="removeProductFromCart">