From ab55f33d99706ca071d8d514f98f70bda8961211 Mon Sep 17 00:00:00 2001 From: Nick Date: Sun, 14 Jul 2019 23:37:22 -0400 Subject: [PATCH] feat: editor - warn on leave without save --- client/components/editor.vue | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/client/components/editor.vue b/client/components/editor.vue index 124813dc..5ba575ac 100644 --- a/client/components/editor.vue +++ b/client/components/editor.vue @@ -118,6 +118,7 @@ export default { dialogProgress: false, dialogEditorSelector: false, dialogUnsaved: false, + exitConfirmed: false, initContentParsed: '' } }, @@ -161,6 +162,14 @@ export default { } else { this.currentEditor = `editor${_.startCase(this.initEditor || 'markdown')}` } + + window.onbeforeunload = () => { + if (!this.exitConfirmed && this.initContentParsed !== this.$store.get('editor/content')) { + return 'You have unsaved edits. Are you sure you want to leave the editor?' + } else { + return undefined + } + } }, methods: { openPropsModal(name) { @@ -263,6 +272,7 @@ export default { exitGo() { this.$store.commit(`loadingStart`, 'editor-close') this.currentEditor = '' + this.exitConfirmed = true _.delay(() => { if (this.$store.get('editor/mode') === 'create') { window.location.assign(`/`)