Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
bhousel committed Oct 23, 2023
1 parent fc27c6e commit d168a51
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
35 changes: 21 additions & 14 deletions modules/modes/SaveMode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
});
}
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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();
}
}

Expand Down Expand Up @@ -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(() => {
Expand Down
10 changes: 6 additions & 4 deletions modules/ui/commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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 || [];
}
Expand Down

0 comments on commit d168a51

Please sign in to comment.