Added timeout to fetch user totals which prevents

Duplicate calls which would be really annoying
This commit is contained in:
Max committed 2022-12-22 01:59:27 +00:00
1 parent 0202d1acda
commit 48c1fa8e69
3 files changed
+28 -18

No files matched your search

+15 -11
View File
@@ -9,6 +9,7 @@ export default new Vuex.Store({
username: null,
nightMode: false,
isUserOnMobile: false,
fetchTotalsTimeout: null,
userTotals: null,
activeSessions: 0,
},
@@ -155,17 +156,20 @@ export default new Vuex.Store({
}
},
actions: {
fetchAndUpdateUserTotals ({ commit }) {
axios.post('/api/user/totals')
.then( ({data}) => {
commit('setUserTotals', data)
})
.catch( error => {
if(error.response && error.response.status == 400){
commit('destroyLoginToken')
location.reload()
}
})
fetchAndUpdateUserTotals ({ commit, state }) {
clearTimeout(state.fetchTotalsTimeout)
state.fetchTotalsTimeout = setTimeout(() => {
axios.post('/api/user/totals')
.then( ({data}) => {
commit('setUserTotals', data)
})
.catch( error => {
if(error.response && error.response.status == 400){
commit('destroyLoginToken')
location.reload()
}
})
}, 100)
}
}
})