Added focus and interaction to refresh notes that have been changed while user was looking away
This commit is contained in:
parent
6d0187ee0a
commit
c972430ef4
@ -399,6 +399,7 @@
|
|||||||
lastNoteHash: null,
|
lastNoteHash: null,
|
||||||
saveDebounce: null, //Prevent save from being called numerous times quickly
|
saveDebounce: null, //Prevent save from being called numerous times quickly
|
||||||
updated: 'Never',
|
updated: 'Never',
|
||||||
|
lastInteractionTimestamp:null, //Tracks when note was loaded and last saved/refreshed
|
||||||
editDebounce: null,
|
editDebounce: null,
|
||||||
textChangedDebounce: null,
|
textChangedDebounce: null,
|
||||||
keyPressesCounter: 0, //Determine keys pressed between saves
|
keyPressesCounter: 0, //Determine keys pressed between saves
|
||||||
@ -747,35 +748,8 @@
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
//Set up local data
|
//Setup all responsive vue data
|
||||||
this.currentNoteId = this.noteid
|
this.setupLoadedNoteData(response)
|
||||||
this.rawTextId = response.data.rawTextId
|
|
||||||
this.shareUsername = response.data.shareUsername
|
|
||||||
|
|
||||||
this.created = response.data.created
|
|
||||||
this.updated = response.data.updated
|
|
||||||
this.noteTitle = ''
|
|
||||||
if(response.data.title){
|
|
||||||
this.noteTitle = response.data.title
|
|
||||||
}
|
|
||||||
|
|
||||||
this.noteText = response.data.text
|
|
||||||
this.lastNoteHash = this.hashString( response.data.text )
|
|
||||||
// this.diffNoteText = response.data.text
|
|
||||||
|
|
||||||
//Setup note tags
|
|
||||||
this.allTags = response.data.tags ? response.data.tags.split(','):[]
|
|
||||||
|
|
||||||
//Set up note colors
|
|
||||||
if(response.data.color){
|
|
||||||
this.styleObject = JSON.parse(response.data.color)
|
|
||||||
}
|
|
||||||
|
|
||||||
if(response.data.pinned != null){
|
|
||||||
this.pinned = response.data.pinned
|
|
||||||
}
|
|
||||||
this.archived = response.data.archived
|
|
||||||
this.attachmentCount = response.data.attachment_count
|
|
||||||
|
|
||||||
this.loading = false
|
this.loading = false
|
||||||
|
|
||||||
@ -792,6 +766,43 @@
|
|||||||
console.log('Could not fetch note')
|
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
|
||||||
|
this.shareUsername = response.data.shareUsername
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
this.noteText = response.data.text
|
||||||
|
this.lastNoteHash = this.hashString( response.data.text )
|
||||||
|
// this.diffNoteText = response.data.text
|
||||||
|
|
||||||
|
//Setup note tags
|
||||||
|
this.allTags = response.data.tags ? response.data.tags.split(','):[]
|
||||||
|
|
||||||
|
//Set up note colors
|
||||||
|
if(response.data.color){
|
||||||
|
this.styleObject = JSON.parse(response.data.color)
|
||||||
|
}
|
||||||
|
|
||||||
|
if(response.data.pinned != null){
|
||||||
|
this.pinned = response.data.pinned
|
||||||
|
}
|
||||||
|
this.archived = response.data.archived
|
||||||
|
this.attachmentCount = response.data.attachment_count
|
||||||
|
|
||||||
|
return true
|
||||||
|
|
||||||
|
},
|
||||||
//Called on squire event for keyup
|
//Called on squire event for keyup
|
||||||
diffText(event){
|
diffText(event){
|
||||||
|
|
||||||
@ -915,6 +926,7 @@
|
|||||||
axios.post('/api/note/update', postData).then( response => {
|
axios.post('/api/note/update', postData).then( response => {
|
||||||
this.statusText = 'saved'
|
this.statusText = 'saved'
|
||||||
this.updated = +new Date
|
this.updated = +new Date
|
||||||
|
this.lastInteractionTimestamp = +new Date
|
||||||
this.modified = true
|
this.modified = true
|
||||||
this.diffsApplied = 0
|
this.diffsApplied = 0
|
||||||
|
|
||||||
@ -927,23 +939,35 @@
|
|||||||
},
|
},
|
||||||
checkForUpdatedNote(){
|
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 user leaves page then returns to page, reload the first batch
|
||||||
if(this.lastVisibilityState == 'hidden' && document.visibilityState == 'visible'){
|
if(this.lastVisibilityState == 'hidden' && document.visibilityState == 'visible' && checkForUpdateTimeout){
|
||||||
// console.log('Checking for note updates after visibility change.')
|
|
||||||
|
|
||||||
const postData = {
|
//Focus Regained on Note, check for update
|
||||||
noteId:this.currentNoteId,
|
axios.post('/api/note/get', { 'noteId': this.noteid })
|
||||||
text:this.getText(),
|
.then(response => {
|
||||||
updated: this.updated
|
|
||||||
}
|
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.lastVisibilityState = document.visibilityState
|
||||||
|
this.lastInteractionTimestamp = +new Date
|
||||||
|
|
||||||
},
|
},
|
||||||
hashString(inText){
|
hashString(inText){
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user