Added focus and interaction to refresh notes that have been changed while user was looking away
This commit is contained in:
parent
bc44b3db9a
commit
0c4f6e94c1
@ -399,6 +399,7 @@
|
||||
lastNoteHash: null,
|
||||
saveDebounce: null, //Prevent save from being called numerous times quickly
|
||||
updated: 'Never',
|
||||
lastInteractionTimestamp:null, //Tracks when note was loaded and last saved/refreshed
|
||||
editDebounce: null,
|
||||
textChangedDebounce: null,
|
||||
keyPressesCounter: 0, //Determine keys pressed between saves
|
||||
@ -747,6 +748,27 @@
|
||||
return
|
||||
}
|
||||
|
||||
//Setup all responsive vue data
|
||||
this.setupLoadedNoteData(response)
|
||||
|
||||
this.loading = false
|
||||
|
||||
this.$nextTick(() => {
|
||||
|
||||
//Adjust note title size after load
|
||||
this.titleResize()
|
||||
this.initSquire()
|
||||
})
|
||||
|
||||
})
|
||||
.catch(error => { this.$bus.$emit('notification', 'Failed to Open Note') })
|
||||
} else {
|
||||
console.log('Could not fetch note')
|
||||
}
|
||||
},
|
||||
setupLoadedNoteData(response){
|
||||
//All the data returned by the server, setup locally in vue component
|
||||
|
||||
//Set up local data
|
||||
this.currentNoteId = this.noteid
|
||||
this.rawTextId = response.data.rawTextId
|
||||
@ -754,6 +776,7 @@
|
||||
|
||||
this.created = response.data.created
|
||||
this.updated = response.data.updated
|
||||
this.lastInteractionTimestamp = +new Date
|
||||
this.noteTitle = ''
|
||||
if(response.data.title){
|
||||
this.noteTitle = response.data.title
|
||||
@ -777,20 +800,8 @@
|
||||
this.archived = response.data.archived
|
||||
this.attachmentCount = response.data.attachment_count
|
||||
|
||||
this.loading = false
|
||||
return true
|
||||
|
||||
this.$nextTick(() => {
|
||||
|
||||
//Adjust note title size after load
|
||||
this.titleResize()
|
||||
this.initSquire()
|
||||
})
|
||||
|
||||
})
|
||||
.catch(error => { this.$bus.$emit('notification', 'Failed to Open Note') })
|
||||
} else {
|
||||
console.log('Could not fetch note')
|
||||
}
|
||||
},
|
||||
//Called on squire event for keyup
|
||||
diffText(event){
|
||||
@ -915,6 +926,7 @@
|
||||
axios.post('/api/note/update', postData).then( response => {
|
||||
this.statusText = 'saved'
|
||||
this.updated = +new Date
|
||||
this.lastInteractionTimestamp = +new Date
|
||||
this.modified = true
|
||||
this.diffsApplied = 0
|
||||
|
||||
@ -927,23 +939,35 @@
|
||||
},
|
||||
checkForUpdatedNote(){
|
||||
|
||||
const now = +new Date
|
||||
//Only check every 3 seconds
|
||||
const checkForUpdateTimeout = now - this.lastInteractionTimestamp > (2 * 1000)
|
||||
|
||||
//If user leaves page then returns to page, reload the first batch
|
||||
if(this.lastVisibilityState == 'hidden' && document.visibilityState == 'visible'){
|
||||
// console.log('Checking for note updates after visibility change.')
|
||||
if(this.lastVisibilityState == 'hidden' && document.visibilityState == 'visible' && checkForUpdateTimeout){
|
||||
|
||||
const postData = {
|
||||
noteId:this.currentNoteId,
|
||||
text:this.getText(),
|
||||
updated: this.updated
|
||||
//Focus Regained on Note, check for update
|
||||
axios.post('/api/note/get', { 'noteId': this.noteid })
|
||||
.then(response => {
|
||||
|
||||
const serverTextHash = this.hashString( response.data.text )
|
||||
|
||||
if(this.lastNoteHash != serverTextHash){
|
||||
// console.log('note was changed UPDATE THAT BITCH!!!!')
|
||||
this.setupLoadedNoteData(response)
|
||||
|
||||
//Manually set squire text to show
|
||||
this.setText(this.noteText)
|
||||
}
|
||||
|
||||
console.log('Focus regained with note open.')
|
||||
console.log('Attempting to fix diff text. fix this. Search spleen')
|
||||
// return
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
//Track visibility state
|
||||
//Keep track of visibility change and last interaction time
|
||||
this.lastVisibilityState = document.visibilityState
|
||||
this.lastInteractionTimestamp = +new Date
|
||||
|
||||
},
|
||||
hashString(inText){
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user