Added timeout to fetch user totals which prevents

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

View File

@ -227,10 +227,12 @@
},
pinNote(){ //togglePinned() <- old name
this.showWorking = true
let postData = {'pinned': !this.note.pinned, 'noteId':this.note.id}
this.note.pinned = this.note.pinned == 1 ? 0:1
let postData = {'pinned': this.note.pinned, 'noteId':this.note.id}
axios.post('/api/note/setpinned', postData)
.then(data => {
this.showWorking = false
// this event is triggered by the server after note is saved
// this.$bus.$emit('update_single_note', this.note.id)
})
.catch(error => { this.$bus.$emit('notification', 'Failed to Pin Note') })
@ -246,11 +248,10 @@
//Show message so no one worries where note went
let message = 'Moved to Archive'
if(postData.archived != 1){
message = 'Moved to main list'
message = 'Moved out of Archive'
}
this.$bus.$emit('notification', message)
// this.$bus.$emit('update_single_note', this.note.id)
this.$bus.$emit('update_single_note', this.note.id)
})
.catch(error => { this.$bus.$emit('notification', 'Failed to Archive Note') })
},
@ -265,9 +266,10 @@
//Show message so no one worries where note went
let message = 'Moved to Trash'
if(postData.trashed == 0){
message = 'Moved to main list'
message = 'Moved out of Trash'
}
this.$bus.$emit('notification', message)
this.$bus.$emit('update_single_note', this.note.id)
})
.catch(error => { this.$bus.$emit('notification', 'Failed to Trash Note') })

View File

@ -127,7 +127,7 @@
:data="note"
:title-view="titleView || isFloatingList"
:currently-open="openNotes.includes(note.id)"
:key="note.id + note.color + '-' +note.title.length + '-' +note.subtext.length + '-' + note.tag_count + note.updated"
:key="note.id + note.color + '-' +note.title.length + '-' +note.subtext.length + '-' + note.tag_count + note.updated + note.archived + note.pinned + note.trashed"
/>
</div>
</div>
@ -564,16 +564,20 @@
// @TODO Don't even trigger this if the note wasn't changed
updateSingleNote(noteId, focuseAndAnimate = true){
console.log('updating single note', noteId)
noteId = parseInt(noteId)
//Find local note, if it exists; continue
let note = null
if(this.$refs['note-'+noteId] && this.$refs['note-'+noteId][0] && this.$refs['note-'+noteId][0].note){
if(this.$refs['note-'+noteId]?.[0]?.note){
note = this.$refs['note-'+noteId][0].note
//Show that note is working on updating
this.$refs['note-'+noteId][0].showWorking = true
}
this.rebuildNoteCategorise()
// return
//Lookup one note using passed in ID
const postData = {

View File

@ -9,6 +9,7 @@ export default new Vuex.Store({
username: null,
nightMode: false,
isUserOnMobile: false,
fetchTotalsTimeout: null,
userTotals: null,
activeSessions: 0,
},
@ -155,7 +156,9 @@ export default new Vuex.Store({
}
},
actions: {
fetchAndUpdateUserTotals ({ commit }) {
fetchAndUpdateUserTotals ({ commit, state }) {
clearTimeout(state.fetchTotalsTimeout)
state.fetchTotalsTimeout = setTimeout(() => {
axios.post('/api/user/totals')
.then( ({data}) => {
commit('setUserTotals', data)
@ -166,6 +169,7 @@ export default new Vuex.Store({
location.reload()
}
})
}, 100)
}
}
})