From 79ce34467c8ebd949734800e6438dc09bfb83df5 Mon Sep 17 00:00:00 2001 From: Vlad Stan Date: Thu, 13 Jul 2023 18:39:07 +0300 Subject: [PATCH] feat: show market categories --- static/js/market.js | 13 +++++++++++++ templates/nostrmarket/market.html | 24 +++++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/static/js/market.js b/static/js/market.js index 2a4a67e..2da5780 100644 --- a/static/js/market.js +++ b/static/js/market.js @@ -148,6 +148,19 @@ const market = async () => { allCartsItemCount() { return this.shoppingCarts.map(s => s.products).flat().reduce((t, p) => t + p.orderedQuantity, 0) + }, + + allCategories() { + const categories = this.products.map(p => p.categories).flat().filter(c => !!c) + const countedCategories = categories.reduce((all, c) => { + all[c] = (all[c] || 0) + 1 + return all + }, {}) + const x = Object.keys(countedCategories) + .map(category => ({ category, count: countedCategories[category] })) + .sort((a,b) => b.count - a.count) + console.log('### x', x) + return x } }, async created() { diff --git a/templates/nostrmarket/market.html b/templates/nostrmarket/market.html index c2616db..f21ed93 100644 --- a/templates/nostrmarket/market.html +++ b/templates/nostrmarket/market.html @@ -159,7 +159,6 @@
-
@@ -204,7 +203,30 @@
+
+
+
+
+
+
+
+ + + +
+
+
+
+ +
+
+