From 6c02e58f84cede98e3c9c30f21d9490df37a154b Mon Sep 17 00:00:00 2001 From: Vlad Stan Date: Wed, 5 Jul 2023 14:43:59 +0300 Subject: [PATCH] feat: basic `market-config` component --- .../market-config/market-config.html | 55 +++++++++++++++++ .../components/market-config/market-config.js | 61 +++++++++++++++++++ static/js/market.js | 4 +- templates/nostrmarket/market.html | 7 ++- 4 files changed, 124 insertions(+), 3 deletions(-) create mode 100644 static/components/market-config/market-config.html create mode 100644 static/components/market-config/market-config.js diff --git a/static/components/market-config/market-config.html b/static/components/market-config/market-config.html new file mode 100644 index 0000000..d5e9a6e --- /dev/null +++ b/static/components/market-config/market-config.html @@ -0,0 +1,55 @@ + +
+
+ + + + + + + + +
+ + + + + + + + + + + + + + {{ profiles.get(pub).name + }} + {{ `${pub.slice(0, 5)}...${pub.slice(-5)}` + }} + {{ pub }} + + + + + + + +
+
+ +
+ Relays +
+
+ +
+ Marketplace +
+
+
+
+
+ +
\ No newline at end of file diff --git a/static/components/market-config/market-config.js b/static/components/market-config/market-config.js new file mode 100644 index 0000000..aa2bf7b --- /dev/null +++ b/static/components/market-config/market-config.js @@ -0,0 +1,61 @@ +async function marketConfig(path) { + const template = await loadTemplateAsync(path) + Vue.component('market-config', { + name: 'market-config', + props: ['adminkey',], + template, + + data: function () { + return { + tab: 'merchants', + pubkeys: new Set(), + profiles: new Map(), + inputPubkey: null, + } + }, + methods: { + async addPubkey(pubkey) { + if (!pubkey) { + pubkey = String(this.inputPubkey).trim() + } + let regExp = /^#([0-9a-f]{3}){1,2}$/i + if (pubkey.startsWith('n')) { + try { + let { type, data } = NostrTools.nip19.decode(pubkey) + if (type === 'npub') pubkey = data + else if (type === 'nprofile') { + pubkey = data.pubkey + givenRelays = data.relays + } + } catch (err) { + console.error(err) + } + } else if (regExp.test(pubkey)) { + pubkey = pubkey + } + this.pubkeys.add(pubkey) + this.inputPubkey = null + this.$q.localStorage.set( + `diagonAlley.merchants`, + Array.from(this.pubkeys) + ) + // this.initNostr()// todo: emit + }, + removePubkey(pubkey) { + // Needs a hack for Vue reactivity + let pubkeys = this.pubkeys + pubkeys.delete(pubkey) + this.profiles.delete(pubkey) + this.pubkeys = new Set(Array.from(pubkeys)) + this.$q.localStorage.set( + `diagonAlley.merchants`, + Array.from(this.pubkeys) + ) + // this.initNostr() // todo: emit + }, + }, + created: async function () { + + } + }) +} diff --git a/static/js/market.js b/static/js/market.js index fac2655..b158000 100644 --- a/static/js/market.js +++ b/static/js/market.js @@ -30,7 +30,8 @@ const market = async () => { customerStall('static/components/customer-stall/customer-stall.html'), productDetail('static/components/product-detail/product-detail.html'), shoppingCart('static/components/shopping-cart/shopping-cart.html'), - chatDialog('static/components/chat-dialog/chat-dialog.html') + chatDialog('static/components/chat-dialog/chat-dialog.html'), + marketConfig('static/components/market-config/market-config.html') ]) new Vue({ @@ -47,6 +48,7 @@ const market = async () => { key: null } }, + showMarketConfig: false, searchNostr: false, drawer: true, pubkeys: new Set(), diff --git a/templates/nostrmarket/market.html b/templates/nostrmarket/market.html index 94208b8..71dc336 100644 --- a/templates/nostrmarket/market.html +++ b/templates/nostrmarket/market.html @@ -154,6 +154,7 @@ +