prevent user preference store from spamming API requests

This commit is contained in:
vabene1111
2023-02-16 23:21:39 +01:00
parent c78c615372
commit 0dc6bed7ad

View File

@@ -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
})
}
},
},
})