Skip to content

Commit

Permalink
fix: #11
Browse files Browse the repository at this point in the history
  • Loading branch information
ttntm committed Dec 7, 2021
1 parent 7608f4d commit 810360e
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/views/RecipeEditable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@
}
}
const onEditClose = (e: BeforeUnloadEvent) => {
if (!noChanges.value && !isSaving.value) {
e.preventDefault() // FF
e.returnValue = '' // Chrome
} else {
delete e['returnValue']
}
}
const saveRecipe = async () => {
const required = ['title', 'description', 'category', 'diet', 'ingredients', 'body']
Expand Down Expand Up @@ -161,7 +170,10 @@
if (current.title) document.title = `Editing: ${current.title} - recept0r`
})
onMounted(() => mode.value && mode.value !== 'edit' ? title.value.focus() : false)
onMounted(() => {
if (mode.value && mode.value !== 'edit') title.value.focus()
window.addEventListener('beforeunload', onEditClose)
})
onBeforeRouteLeave((to, from) => {
if (loggedIn.value && !noChanges.value && !isSaving.value) {
Expand Down

0 comments on commit 810360e

Please sign in to comment.