From 69476babe3d22cd359cfbfa9dda60d26808798b0 Mon Sep 17 00:00:00 2001 From: Christian Wolf Date: Tue, 17 Oct 2023 12:56:51 +0200 Subject: [PATCH 1/6] Prevent loading config on start of app Signed-off-by: Christian Wolf --- src/components/SettingsDialog.vue | 90 +++++++++++++++---------------- src/guest.js | 2 + src/main.js | 2 + 3 files changed, 48 insertions(+), 46 deletions(-) diff --git a/src/components/SettingsDialog.vue b/src/components/SettingsDialog.vue index 5e7a4edde..9100fb72e 100644 --- a/src/components/SettingsDialog.vue +++ b/src/components/SettingsDialog.vue @@ -188,6 +188,8 @@ import { showSimpleAlertModal } from "cookbook/js/modals" import { enableLogging } from "cookbook/js/logging" +import Vue from "vue" + export const SHOW_SETTINGS_EVENT = "show-settings" const INFO_BLOCK_KEYS = [ @@ -221,20 +223,25 @@ export default { isOpen: false, printImage: false, recipeFolder: "", - resetPrintImage: true, + resetPrintImage: false, showTagCloudInRecipeList: true, - resetTagCloud: true, + resetTagCloud: false, scanningLibrary: false, // By setting the reset value initially to true, it will skip one watch event // (the one when config is loaded at page load) - resetInterval: true, + resetInterval: false, updateInterval: 0, visibleInfoBlocks: [...INFO_BLOCK_KEYS], resetVisibleInfoBlocks: true, + writeChanges: true, } }, watch: { async printImage(newVal, oldVal) { + if (! this.writeChanges) { + return + } + // Avoid infinite loop on page load and when reseting value after failed submit if (this.resetPrintImage) { this.resetPrintImage = false @@ -254,11 +261,19 @@ export default { }, // eslint-disable-next-line no-unused-vars showTagCloudInRecipeList(newVal, oldVal) { + if (! this.writeChanges) { + return + } + this.$store.dispatch("setShowTagCloudInRecipeList", { showTagCloud: newVal, }) }, async updateInterval(newVal, oldVal) { + if (! this.writeChanges) { + return + } + // Avoid infinite loop on page load and when reseting value after failed submit if (this.resetInterval) { this.resetInterval = false @@ -281,6 +296,10 @@ export default { } }, async visibleInfoBlocks(newVal, oldVal) { + if (!this.writeChanges) { + return + } + // Avoid infinite loop on page load and when reseting value after failed submit if (this.resetVisibleInfoBlocks) { this.resetVisibleInfoBlocks = false @@ -303,13 +322,33 @@ export default { }, }, mounted() { - this.setup() - subscribe(SHOW_SETTINGS_EVENT, this.handleShowSettings) }, methods: { handleShowSettings() { this.isOpen = true + + // Temporarily disable the storage of data + this.writeChanges = false + + const { config } = this.$store.state + this.resetPrintImage = false + this.resetVisibleInfoBlocks = false + + if (!config) { + throw new Error() + } + + this.printImage = config.print_image + this.visibleInfoBlocks = visibleInfoBlocksDecode( + config.visibleInfoBlocks, + ) + this.showTagCloudInRecipeList = + this.$store.state.localSettings.showTagCloudInRecipeList + this.updateInterval = config.update_interval + this.recipeFolder = config.folder + + Vue.nextTick(() => { this.writeChanges = true }) }, /** @@ -348,36 +387,6 @@ export default { }) }, - /** - * Initial setup - */ - async setup() { - try { - await this.$store.dispatch("refreshConfig") - const { config } = this.$store.state - this.resetPrintImage = false - this.resetVisibleInfoBlocks = false - - if (!config) { - throw new Error() - } - - this.printImage = config.print_image - this.visibleInfoBlocks = visibleInfoBlocksDecode( - config.visibleInfoBlocks, - ) - this.showTagCloudInRecipeList = - this.$store.state.localSettings.showTagCloudInRecipeList - this.updateInterval = config.update_interval - this.recipeFolder = config.folder - } catch (err) { - this.$log.error("Error setting up SettingsDialog", err) - await showSimpleAlertModal( - t("cookbook", "Loading config failed"), - ) - } - }, - /** * Reindex all recipes */ @@ -439,15 +448,4 @@ export default { width: 100%; } -/* #app-settings .button { */ -/* z-index: 2; */ -/* height: 44px; */ -/* padding: 0; */ -/* border-radius: var(--border-radius); */ -/* } */ - -/* #app-settings .button p { */ -/* margin: auto; */ -/* font-size: 13px; */ -/* } */ diff --git a/src/guest.js b/src/guest.js index 474b9c323..4be575087 100644 --- a/src/guest.js +++ b/src/guest.js @@ -27,6 +27,8 @@ Vue.prototype.OC = OC // Pass translation engine to Vue Vue.prototype.t = window.t +store.dispatch('refreshConfig') + // Start the app once document is done loading const App = Vue.extend(AppInvalidGuest) new App({ diff --git a/src/main.js b/src/main.js index c8ee45f86..91661c42d 100644 --- a/src/main.js +++ b/src/main.js @@ -57,6 +57,8 @@ Vue.use(ModalDialogs) setupLogging(Vue) +store.dispatch('refreshConfig') + // Pass translation engine to Vue Vue.prototype.t = window.t From 04debfadda361cb011ab08940422a79586280f39 Mon Sep 17 00:00:00 2001 From: Christian Wolf Date: Wed, 15 Nov 2023 19:57:02 +0100 Subject: [PATCH 2/6] Remove additional fetching of config after setting Signed-off-by: Christian Wolf --- src/components/SettingsDialog.vue | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/components/SettingsDialog.vue b/src/components/SettingsDialog.vue index 9100fb72e..73b3346fc 100644 --- a/src/components/SettingsDialog.vue +++ b/src/components/SettingsDialog.vue @@ -281,7 +281,6 @@ export default { } try { await api.config.updateInterval.update(newVal) - // Should this check the response of the query? To catch some errors that redirect the page } catch { await showSimpleAlertModal( // prettier-ignore @@ -308,8 +307,6 @@ export default { try { const data = visibleInfoBlocksEncode(newVal) await api.config.visibleInfoBlocks.update(data) - await this.$store.dispatch("refreshConfig") - // Should this check the response of the query? To catch some errors that redirect the page } catch (err) { // eslint-disable-next-line no-console console.error("Error while trying to save info blocks", err) From 922fd6019f9d2e5ce647ce7d2d89a20f5ffc54f2 Mon Sep 17 00:00:00 2001 From: Christian Wolf Date: Wed, 15 Nov 2023 20:08:07 +0100 Subject: [PATCH 3/6] Drop obsolete data protectors as no longer needed Signed-off-by: Christian Wolf --- src/components/SettingsDialog.vue | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/src/components/SettingsDialog.vue b/src/components/SettingsDialog.vue index 73b3346fc..2d7a57c0b 100644 --- a/src/components/SettingsDialog.vue +++ b/src/components/SettingsDialog.vue @@ -223,16 +223,10 @@ export default { isOpen: false, printImage: false, recipeFolder: "", - resetPrintImage: false, showTagCloudInRecipeList: true, - resetTagCloud: false, scanningLibrary: false, - // By setting the reset value initially to true, it will skip one watch event - // (the one when config is loaded at page load) - resetInterval: false, updateInterval: 0, visibleInfoBlocks: [...INFO_BLOCK_KEYS], - resetVisibleInfoBlocks: true, writeChanges: true, } }, @@ -242,11 +236,6 @@ export default { return } - // Avoid infinite loop on page load and when reseting value after failed submit - if (this.resetPrintImage) { - this.resetPrintImage = false - return - } try { await api.config.printImage.update(newVal) // Should this check the response of the query? To catch some errors that redirect the page @@ -255,7 +244,6 @@ export default { // prettier-ignore t("cookbook","Could not set preference for image printing"), ) - this.resetPrintImage = true this.printImage = oldVal } }, @@ -274,11 +262,6 @@ export default { return } - // Avoid infinite loop on page load and when reseting value after failed submit - if (this.resetInterval) { - this.resetInterval = false - return - } try { await api.config.updateInterval.update(newVal) } catch { @@ -290,7 +273,6 @@ export default { } ), ) - this.resetInterval = true this.updateInterval = oldVal } }, @@ -299,11 +281,6 @@ export default { return } - // Avoid infinite loop on page load and when reseting value after failed submit - if (this.resetVisibleInfoBlocks) { - this.resetVisibleInfoBlocks = false - return - } try { const data = visibleInfoBlocksEncode(newVal) await api.config.visibleInfoBlocks.update(data) @@ -313,7 +290,6 @@ export default { await showSimpleAlertModal( t("cookbook", "Could not save visible info blocks"), ) - this.resetVisibleInfoBlocks = true this.visibleInfoBlocks = oldVal } }, @@ -329,8 +305,6 @@ export default { this.writeChanges = false const { config } = this.$store.state - this.resetPrintImage = false - this.resetVisibleInfoBlocks = false if (!config) { throw new Error() From 839a627f73655934a9e4cbf3a078e0eef6f306b1 Mon Sep 17 00:00:00 2001 From: Christian Wolf Date: Wed, 15 Nov 2023 20:26:07 +0100 Subject: [PATCH 4/6] Make prettier and eslint happy Signed-off-by: Christian Wolf --- src/components/RecipeView.vue | 2 +- src/components/SettingsDialog.vue | 13 +++++++------ src/guest.js | 2 +- src/main.js | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/components/RecipeView.vue b/src/components/RecipeView.vue index ac37d5e1b..c8d97883c 100644 --- a/src/components/RecipeView.vue +++ b/src/components/RecipeView.vue @@ -130,9 +130,9 @@