From 0dc6bed7ad88bcbdae88d1d3f6faf90caf5cc30a Mon Sep 17 00:00:00 2001 From: vabene1111 Date: Thu, 16 Feb 2023 23:21:39 +0100 Subject: [PATCH] prevent user preference store from spamming API requests --- vue/src/stores/UserPreferenceStore.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/vue/src/stores/UserPreferenceStore.js b/vue/src/stores/UserPreferenceStore.js index b04e618a1..dbb3939e9 100644 --- a/vue/src/stores/UserPreferenceStore.js +++ b/vue/src/stores/UserPreferenceStore.js @@ -9,6 +9,7 @@ export const useUserPreferenceStore = defineStore(_STORE_ID, { state: () => ({ data: null, updated_at: null, + currently_updating: false, }), getters: { @@ -68,11 +69,17 @@ export const useUserPreferenceStore = defineStore(_STORE_ID, { */ refreshFromAPI() { let apiClient = new ApiApiFactory() - return apiClient.retrieveUserPreference(localStorage.getItem('USER_ID')).then(r => { - this.data = r.data - this.updated_at = new Date() - return this.data - }) + if(!this.currently_updating){ + this.currently_updating = true + return apiClient.retrieveUserPreference(localStorage.getItem('USER_ID')).then(r => { + this.data = r.data + this.updated_at = new Date() + this.currently_updating = false + return this.data + }).catch(err => { + this.currently_updating = false + }) + } }, }, }) \ No newline at end of file