From d8721a0785a273ec547aa1b33b55599663a30024 Mon Sep 17 00:00:00 2001 From: Vlad Stan Date: Tue, 18 Jul 2023 09:31:07 +0300 Subject: [PATCH] refactor: extract `applyUiConfigs` --- static/js/market.js | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/static/js/market.js b/static/js/market.js index aa4ad14..3fcd54b 100644 --- a/static/js/market.js +++ b/static/js/market.js @@ -280,12 +280,8 @@ const market = async () => { const uiConfig = this.$q.localStorage.getItem('nostrmarket.marketplace-config') || {} // trigger the `watch` logic this.config = { ...this.config, opts: { ...this.config.opts, ...uiConfig } } - if (this.config?.opts?.ui?.theme) { - document.body.setAttribute('data-theme', this.config.opts.ui.theme) - } + this.applyUiConfigs(this.config) - console.log('### uiConfig', uiConfig) - console.log('### this.config', this.config) const prefix = 'nostrmarket.orders.' const orderKeys = this.$q.localStorage.getAllKeys().filter(k => k.startsWith(prefix)) @@ -296,8 +292,17 @@ const market = async () => { const relays = this.$q.localStorage.getItem('nostrmarket.relays') this.relays = new Set(relays?.length ? relays : defaultRelays) - + console.log('#### relays', relays, this.relays) }, + applyUiConfigs(config = {}) { + if (config.opts?.ui?.theme) { + document.body.setAttribute('data-theme', this.config.opts.ui.theme) + } + if (config.opts?.ui?.darkMode) { + // tood + } + }, + async deleteAccount() { await LNbits.utils .confirmDialog( @@ -353,14 +358,10 @@ const market = async () => { console.log('### updateUiConfig', updateData) const { name, about, ui } = updateData this.config.opts = { ...this.config.opts, name, about, ui } - if (ui.theme) { - document.body.setAttribute('data-theme', ui.theme) - } + this.applyUiConfigs(this.config) this.$q.localStorage.set('nostrmarket.marketplace-config', { name, about, ui }) - - if (!this.account?.privkey) return const merchants = Array.from(this.merchants.map(m => m.publicKey)) @@ -508,9 +509,7 @@ const market = async () => { .map(m => ({ publicKey: m, profile: null })) this.merchants.push(...extraMerchants) - // change theme - const { theme } = this.config.opts?.ui - theme && document.body.setAttribute('data-theme', theme) + this.applyUiConfigs(this.config) } catch (error) { console.warn(error) }