Skip to content

Commit

Permalink
Merge pull request #4840 from anaswaratrajan/warn-before-close
Browse files Browse the repository at this point in the history
Added upload pending prompt on close/reload
  • Loading branch information
kulmann authored May 28, 2021
2 parents f69d237 + 1a09df6 commit 4928f82
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Enhancement: Prompts leaving user about pending uploads

Added an unload event listener that detects closes/ reloads/ navigates to another URL.
Added prompt that ask for confirmation to leave site on unload events if uploads pending.
Removed the event listener before destroy of component.

https://github.com/owncloud/web/issues/2590
https://github.com/owncloud/web/pull/4840
14 changes: 14 additions & 0 deletions packages/web-app-files/src/components/UploadProgress.vue
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ export default {
} else {
return 100
}
},
uploadPending() {
return this.totalUploadProgress < 100
}
},
watch: {
Expand All @@ -124,10 +128,20 @@ export default {
this.delayForScreenreader(() => this.$refs.progressbar.$el.focus())
})
})
window.addEventListener('beforeunload', this.handlerClose)
},
beforeDestroy() {
window.removeEventListener('beforeunload', this.handlerClose)
},
methods: {
$_toggleExpanded() {
this.expanded = !this.expanded
},
handlerClose(event) {
if (this.uploadPending) {
event.preventDefault()
event.returnValue = ''
}
}
}
}
Expand Down

0 comments on commit 4928f82

Please sign in to comment.