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

Fix toggling edit mode with no changes #1008

Merged
merged 1 commit into from
Nov 17, 2023
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
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