mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2026-01-04 21:58:54 -05:00
prevent user preference store from spamming API requests
This commit is contained in:
@@ -9,6 +9,7 @@ export const useUserPreferenceStore = defineStore(_STORE_ID, {
|
|||||||
state: () => ({
|
state: () => ({
|
||||||
data: null,
|
data: null,
|
||||||
updated_at: null,
|
updated_at: null,
|
||||||
|
currently_updating: false,
|
||||||
}),
|
}),
|
||||||
getters: {
|
getters: {
|
||||||
|
|
||||||
@@ -68,11 +69,17 @@ export const useUserPreferenceStore = defineStore(_STORE_ID, {
|
|||||||
*/
|
*/
|
||||||
refreshFromAPI() {
|
refreshFromAPI() {
|
||||||
let apiClient = new ApiApiFactory()
|
let apiClient = new ApiApiFactory()
|
||||||
return apiClient.retrieveUserPreference(localStorage.getItem('USER_ID')).then(r => {
|
if(!this.currently_updating){
|
||||||
this.data = r.data
|
this.currently_updating = true
|
||||||
this.updated_at = new Date()
|
return apiClient.retrieveUserPreference(localStorage.getItem('USER_ID')).then(r => {
|
||||||
return this.data
|
this.data = r.data
|
||||||
})
|
this.updated_at = new Date()
|
||||||
|
this.currently_updating = false
|
||||||
|
return this.data
|
||||||
|
}).catch(err => {
|
||||||
|
this.currently_updating = false
|
||||||
|
})
|
||||||
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
Reference in New Issue
Block a user