From e95412a03cb84d4d835047d44e55a2900cdfb0d1 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Mon, 31 May 2021 14:16:37 +0300 Subject: [PATCH 1/2] fix BooleanSetting and ChoiceSetting not working properly on initial launch as anon visitor (would show all as changed, empty selects) --- src/components/settings_modal/helpers/boolean_setting.js | 5 ++++- src/components/settings_modal/helpers/choice_setting.js | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/components/settings_modal/helpers/boolean_setting.js b/src/components/settings_modal/helpers/boolean_setting.js index 1dda49f2..dea77e10 100644 --- a/src/components/settings_modal/helpers/boolean_setting.js +++ b/src/components/settings_modal/helpers/boolean_setting.js @@ -18,8 +18,11 @@ export default { state () { return get(this.$parent, this.path) }, + defaultState () { + return get(this.$parent, this.pathDefault) + }, isChanged () { - return get(this.$parent, this.path) !== get(this.$parent, this.pathDefault) + return this.state !== undefined && this.state !== this.defaultState } }, methods: { diff --git a/src/components/settings_modal/helpers/choice_setting.js b/src/components/settings_modal/helpers/choice_setting.js index 042e8106..f4387e62 100644 --- a/src/components/settings_modal/helpers/choice_setting.js +++ b/src/components/settings_modal/helpers/choice_setting.js @@ -17,13 +17,13 @@ export default { return [firstSegment + 'DefaultValue', ...rest].join('.') }, state () { - return get(this.$parent, this.path) + return get(this.$parent, this.path) || get(this.$parent, this.pathDefault) }, defaultState () { return get(this.$parent, this.pathDefault) }, isChanged () { - return get(this.$parent, this.path) !== get(this.$parent, this.pathDefault) + return this.state !== undefined && this.state !== this.defaultState } }, methods: { From 32d1a0e1813e706a298871361123636187cde9bc Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Mon, 31 May 2021 14:22:08 +0300 Subject: [PATCH 2/2] better approach --- src/components/settings_modal/helpers/boolean_setting.js | 9 +++++++-- src/components/settings_modal/helpers/choice_setting.js | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/components/settings_modal/helpers/boolean_setting.js b/src/components/settings_modal/helpers/boolean_setting.js index dea77e10..5c52f697 100644 --- a/src/components/settings_modal/helpers/boolean_setting.js +++ b/src/components/settings_modal/helpers/boolean_setting.js @@ -16,13 +16,18 @@ export default { return [firstSegment + 'DefaultValue', ...rest].join('.') }, state () { - return get(this.$parent, this.path) + const value = get(this.$parent, this.path) + if (value === undefined) { + return this.defaultState + } else { + return value + } }, defaultState () { return get(this.$parent, this.pathDefault) }, isChanged () { - return this.state !== undefined && this.state !== this.defaultState + return this.state !== this.defaultState } }, methods: { diff --git a/src/components/settings_modal/helpers/choice_setting.js b/src/components/settings_modal/helpers/choice_setting.js index f4387e62..a15f6bac 100644 --- a/src/components/settings_modal/helpers/choice_setting.js +++ b/src/components/settings_modal/helpers/choice_setting.js @@ -17,13 +17,18 @@ export default { return [firstSegment + 'DefaultValue', ...rest].join('.') }, state () { - return get(this.$parent, this.path) || get(this.$parent, this.pathDefault) + const value = get(this.$parent, this.path) + if (value === undefined) { + return this.defaultState + } else { + return value + } }, defaultState () { return get(this.$parent, this.pathDefault) }, isChanged () { - return this.state !== undefined && this.state !== this.defaultState + return this.state !== this.defaultState } }, methods: {