Skip to content

Commit

Permalink
Fix toggling edit mode with no changes
Browse files Browse the repository at this point in the history
  • Loading branch information
simon-leech committed Nov 16, 2023
1 parent 6bc6766 commit 2ae1110
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/ui/locations/view.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export default location => {
// New locations should be editable.
!location.new && location.removeEdits()

// Create edit toggle button.
location.editToggle = mapp.utils.html.node`
<button
title = "Enable edits"
Expand All @@ -107,17 +108,26 @@ export default location => {
// Remove on class from button.
e.target.classList.remove('on')
// If there are unsaved edits.
if (location.infoj.some(entry => typeof entry.newValue !== 'undefined')) {
// Ask user whether to save edits.
if (confirm(`Save your changes to this location?`)) {
// Save edits.
await location.update()
// If user does not want to save edits.
} else {
// Remove edits from infoj entries.
location.removeEdits()
}
}
// If there's nothing to save.
else {
// Just remove edits from infoj entries.
location.removeEdits()
}
} else {
Expand Down

0 comments on commit 2ae1110

Please sign in to comment.