From d168a512bddeab83ae069e7842f65588bc9ab873 Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Mon, 23 Oct 2023 17:51:10 -0400 Subject: [PATCH] simplify --- modules/modes/SaveMode.js | 35 +++++++++++++++++++++-------------- modules/ui/commit.js | 10 ++++++---- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/modules/modes/SaveMode.js b/modules/modes/SaveMode.js index c68472fc90..1d373af96d 100644 --- a/modules/modes/SaveMode.js +++ b/modules/modes/SaveMode.js @@ -55,16 +55,19 @@ export class SaveMode extends AbstractMode { * Enters the mode. */ enter() { + const context = this.context; + const osm = context.services.osm; + const sidebar = context.systems.ui.sidebar; + const uploader = context.systems.uploader; + + if (!osm) return false; // can't enter save mode + if (DEBUG) { console.log('SaveMode: entering'); // eslint-disable-line no-console } // Show sidebar - const context = this.context; - context.systems.ui.sidebar.expand(); - - const osm = context.services.osm; - if (!osm) return false; // can't enter save mode + sidebar.expand(); this._active = true; this._wasSuccessfulSave = false; @@ -73,13 +76,13 @@ export class SaveMode extends AbstractMode { .on('cancel', this._cancel); if (osm.authenticated()) { - context.systems.ui.sidebar.show(this._uiCommit); + sidebar.show(this._uiCommit); } else { osm.authenticate(err => { if (err) { this._cancel(); } else { - context.systems.ui.sidebar.show(this._uiCommit); + sidebar.show(this._uiCommit); } }); } @@ -91,7 +94,7 @@ export class SaveMode extends AbstractMode { this._keybindingOn(); context.enableBehaviors(['map-interaction']); - context.systems.uploader + uploader .on('progressChanged', this._progressChanged) .on('resultConflicts', this._resultConflicts) .on('resultErrors', this._resultErrors) @@ -116,10 +119,14 @@ export class SaveMode extends AbstractMode { console.log('SaveMode: exiting'); // eslint-disable-line no-console } + const context = this.context; + const sidebar = context.systems.ui.sidebar; + const uploader = context.systems.uploader; + this._uiCommit.on('cancel', null); this._uiCommit = null; - this.context.systems.uploader + uploader .off('progressChanged', this._progressChanged) .off('resultConflicts', this._resultConflicts) .off('resultErrors', this._resultErrors) @@ -132,13 +139,13 @@ export class SaveMode extends AbstractMode { this._keybindingOff(); this._hideLoading(); - this.context.container().selectAll('.main-content') + context.container().selectAll('.main-content') .classed('active', true) .classed('inactive', false); // After a successful save, we want to leave the "thanks" content in the sidebar if (!this._wasSuccessfulSave) { - this.context.systems.ui.sidebar.hide(); + sidebar.hide(); } } @@ -301,15 +308,15 @@ export class SaveMode extends AbstractMode { */ _resultSuccess(changeset) { const context = this.context; - const ui = context.systems.ui; + const sidebar = context.systems.ui.sidebar; const successContent = this._uiSuccess .changeset(changeset) .location(this._location) - .on('cancel', () => ui.sidebar.hide()); + .on('cancel', () => sidebar.hide()); this._wasSuccessfulSave = true; - ui.sidebar.show(successContent); + sidebar.show(successContent); // Add delay before resetting to allow for postgres replication iD#1646 iD#2678 window.setTimeout(() => { diff --git a/modules/ui/commit.js b/modules/ui/commit.js index 09fc6f62e2..591a96db84 100644 --- a/modules/ui/commit.js +++ b/modules/ui/commit.js @@ -467,9 +467,11 @@ export function uiCommit(context) { if (!d3_select(this).classed('disabled')) { this.blur(); // avoid keeping focus on the button - iD#4641 - for (let key in uploader.changeset.tags) { - // remove any empty keys before upload - if (!key) delete uploader.changeset.tags[key]; + const tags = uploader.changeset.tags; + for (const [k, v] of Object.entries(tags)) { + if (!k || !v) { // remove any empty tags before upload + delete tags[k]; + } } uploader.save(); @@ -608,7 +610,7 @@ export function uiCommit(context) { if (s[0] !== '#') { s = '#' + s; } // prepend '#' let matched = s.match(hashtagRegex); return matched && matched[0]; - }).filter(Boolean); // exclude falsy + }).filter(Boolean); // exclude falsy return matches || []; }