From 43f4228e196da23660cdc26a7a436514ab10f4d4 Mon Sep 17 00:00:00 2001 From: Black Coffee Date: Thu, 29 Sep 2022 12:59:52 +0100 Subject: [PATCH] Bug fix on toggle all --- .../extensions/gerty/templates/gerty/index.html | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lnbits/extensions/gerty/templates/gerty/index.html b/lnbits/extensions/gerty/templates/gerty/index.html index b46fa812..59df4c1e 100644 --- a/lnbits/extensions/gerty/templates/gerty/index.html +++ b/lnbits/extensions/gerty/templates/gerty/index.html @@ -380,6 +380,7 @@ mining: true, lightning: true }, + oldToggleStates: {}, gertys: [], currencyOptions: [ 'USD', @@ -749,15 +750,21 @@ }, watch: { toggleStates: { - handler(toggleStatesValue, oldValue) { + handler(toggleStatesValue) { // Switch all the toggles in each section to the relevant state for (const [toggleKey, toggleValue] of Object.entries(toggleStatesValue)) { - for (const [dpKey, dpValue] of Object.entries(this.formDialog.data.display_preferences)) { - if(dpKey.indexOf(toggleKey) === 0) { - this.formDialog.data.display_preferences[dpKey] = toggleValue + if (this.oldToggleStates[toggleKey] !== toggleValue) { + for (const [dpKey, dpValue] of Object.entries(this.formDialog.data.display_preferences)) { + if (dpKey.indexOf(toggleKey) === 0) { + this.formDialog.data.display_preferences[dpKey] = toggleValue + } } } } + // This is a weird hack we have to use to get VueJS to persist the previous toggle state between + // watches. VueJS passes the old and new values by reference so when comparing objects they + // will have the same values unless we do this + this.oldToggleStates = JSON.parse(JSON.stringify(toggleStatesValue)) }, deep: true }