Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable3.5] fix(composer): Prevent leaving the tab with unsaved changes #9540

Merged
merged 1 commit into from
Apr 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/components/NewMessageModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,15 @@ export default {
if (id) {
this.draftsPromise = Promise.resolve(id)
}
window.addEventListener('beforeunload', this.onBeforeUnload)
},
async mounted() {
await this.$nextTick()
this.updateCookedComposerData()
},
beforeDestroy() {
window.removeEventListener('beforeunload', this.onBeforeUnload)
},
methods: {
handleShow(element) {
this.toolbarElements = [element]
Expand Down Expand Up @@ -474,6 +478,15 @@ export default {
this.updateCookedComposerData()
await this.$store.dispatch('patchComposerData', data)
},
onBeforeUnload(e) {
if (this.canSaveDraft && this.changed) {
e.preventDefault()
e.returnValue = true
this.$store.dispatch('showMessageComposer')
} else {
console.info('No unsaved changes. See you!')
}
},
async onMinimize() {
this.modalFirstOpen = false

Expand Down
Loading