Skip to content
Permalink
Browse files

exercise solution

  • Loading branch information...
hootlex committed Jun 17, 2018
1 parent ca1a88e commit 9c5e3aa941f8f34e2dd91cfa011644de1b9f304f
Showing with 20 additions and 0 deletions.
  1. +20 −0 src/pages/PageThreadEdit.vue
@@ -4,6 +4,7 @@
<h1>Editing <i>{{thread.title}}</i></h1>

<ThreadEditor
ref="editor"
:title="thread.title"
:text="text"
@save="save"
@@ -39,6 +40,12 @@
text () {
const post = this.$store.state.posts[this.thread.firstPostId]
return post ? post.text : null
},
hasUnsavedChanges () {
// this.saved is not required in this implementation because `this.thread.title` and `this.text` are reactive
// Thus `hasUnsavedChanges` will automatically become false when the thread is updated
return this.$refs.editor.form.title !== this.thread.title || this.$refs.editor.form.text !== this.text
}
},
@@ -64,6 +71,19 @@
this.fetchThread({id: this.id})
.then(thread => this.fetchPost({id: thread.firstPostId}))
.then(() => { this.asyncDataStatus_fetched() })
},
beforeRouteLeave (to, from, next) {
if (this.hasUnsavedChanges) {
const confirmed = window.confirm('Are you sure you want to leave? Any unsaved changes will be lost!')
if (confirmed) {
next()
} else {
next(false)
}
} else {
next()
}
}
}
</script>

0 comments on commit 9c5e3aa

Please sign in to comment.
You can’t perform that action at this time.