From f4478548346c54bd27c8b5b3eb1ef70bfc856738 Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Mon, 14 Feb 2022 02:50:21 +0100 Subject: [PATCH] Small refactoring, fix logic which possibly caused #659 (to be confirmed) --- Logic/Osm/Changes.ts | 30 ++++++++++++++---------------- Logic/Osm/ChangesetHandler.ts | 3 +-- Logic/Osm/OsmConnection.ts | 3 +-- Logic/State/UserRelatedState.ts | 1 - UI/AutomatonGui.ts | 1 - test/OsmConnection.spec.ts | 1 - 6 files changed, 16 insertions(+), 23 deletions(-) diff --git a/Logic/Osm/Changes.ts b/Logic/Osm/Changes.ts index f928cc9fdc..c4a24ab3f7 100644 --- a/Logic/Osm/Changes.ts +++ b/Logic/Osm/Changes.ts @@ -104,7 +104,7 @@ export class Changes { * Uploads all the pending changes in one go. * Triggered by the 'PendingChangeUploader'-actor in Actors */ - public async flushChanges(flushreason: string = undefined, openChangeset?: UIEventSource): Promise { + public async flushChanges(flushreason: string = undefined): Promise { if (this.pendingChanges.data.length === 0) { return; } @@ -117,7 +117,7 @@ export class Changes { console.log("Uploading changes due to: ", flushreason) this.isUploading.setData(true) try { - const csNumber = await this.flushChangesAsync(openChangeset) + const csNumber = await this.flushChangesAsync() this.isUploading.setData(false) console.log("Changes flushed. Your changeset is " + csNumber); } catch (e) { @@ -213,7 +213,7 @@ export class Changes { const osmObjects = Utils.NoNull(await Promise.all(neededIds.map(async id => OsmObject.DownloadObjectAsync(id).catch(e => { - console.error("Could not download OSM-object", id, " dropping it from the changes") + console.error("Could not download OSM-object", id, " dropping it from the changes ("+e+")") pending = pending.filter(ch => ch.type + "/" + ch.id !== id) return undefined; })))); @@ -309,7 +309,7 @@ export class Changes { return true; } - private async flushChangesAsync(openChangeset?: UIEventSource): Promise { + private async flushChangesAsync(): Promise { const self = this; try { // At last, we build the changeset and upload @@ -327,18 +327,16 @@ export class Changes { const successes = await Promise.all(Array.from(pendingPerTheme, async ([theme, pendingChanges]) => { try { - if (openChangeset === undefined) { - openChangeset = this.state.osmConnection.GetPreference("current-open-changeset-" + theme).map( - str => { - const n = Number(str); - if (isNaN(n)) { - return undefined - } - return n - }, [], n => "" + n - ); - console.log("Using current-open-changeset-" + theme + " from the preferences, got " + openChangeset.data) - } + const openChangeset = this.state.osmConnection.GetPreference("current-open-changeset-" + theme).map( + str => { + const n = Number(str); + if (isNaN(n)) { + return undefined + } + return n + }, [], n => "" + n + ); + console.log("Using current-open-changeset-" + theme + " from the preferences, got " + openChangeset.data) return await self.flushSelectChanges(pendingChanges, openChangeset); } catch (e) { diff --git a/Logic/Osm/ChangesetHandler.ts b/Logic/Osm/ChangesetHandler.ts index 8ae97632bd..40e2d57579 100644 --- a/Logic/Osm/ChangesetHandler.ts +++ b/Logic/Osm/ChangesetHandler.ts @@ -23,8 +23,7 @@ export class ChangesetHandler { private readonly auth: any; private readonly backend: string; - constructor(layoutName: string, - dryRun: UIEventSource, + constructor(dryRun: UIEventSource, osmConnection: OsmConnection, allElements: ElementStorage, changes: Changes, diff --git a/Logic/Osm/OsmConnection.ts b/Logic/Osm/OsmConnection.ts index 57b16890c9..ef5bb5b5e7 100644 --- a/Logic/Osm/OsmConnection.ts +++ b/Logic/Osm/OsmConnection.ts @@ -67,7 +67,6 @@ export class OsmConnection { changes: Changes, oauth_token?: UIEventSource, // Used to keep multiple changesets open and to write to the correct changeset - layoutName: string, singlePage?: boolean, osmConfiguration?: "osm" | "osm-test", attemptLogin?: true | boolean @@ -103,7 +102,7 @@ export class OsmConnection { this.preferencesHandler = new OsmPreferences(this.auth, this); - this.changesetHandler = new ChangesetHandler(options.layoutName, this._dryRun, this, options.allElements, options.changes, this.auth); + this.changesetHandler = new ChangesetHandler(this._dryRun, this, options.allElements, options.changes, this.auth); if (options.oauth_token?.data !== undefined) { console.log(options.oauth_token.data) const self = this; diff --git a/Logic/State/UserRelatedState.ts b/Logic/State/UserRelatedState.ts index f46eb90d9d..03cc274c6a 100644 --- a/Logic/State/UserRelatedState.ts +++ b/Logic/State/UserRelatedState.ts @@ -42,7 +42,6 @@ export default class UserRelatedState extends ElementsState { undefined, "Used to complete the login" ), - layoutName: layoutToUse?.id, osmConfiguration: <'osm' | 'osm-test'>this.featureSwitchApiURL.data, attemptLogin: options?.attemptLogin }) diff --git a/UI/AutomatonGui.ts b/UI/AutomatonGui.ts index db5d6a6455..cfa42fc883 100644 --- a/UI/AutomatonGui.ts +++ b/UI/AutomatonGui.ts @@ -226,7 +226,6 @@ class AutomatonGui { const osmConnection = new OsmConnection({ allElements: undefined, changes: undefined, - layoutName: "automaton", singlePage: false, oauth_token: QueryParameters.GetQueryParameter("oauth_token", "OAuth token") }); diff --git a/test/OsmConnection.spec.ts b/test/OsmConnection.spec.ts index d21d44e643..597ce9e218 100644 --- a/test/OsmConnection.spec.ts +++ b/test/OsmConnection.spec.ts @@ -19,7 +19,6 @@ export default class OsmConnectionSpec extends T { () => { const osmConn = new OsmConnection({ osmConfiguration: "osm-test", - layoutName: "Unit test", allElements: new ElementStorage(), changes: new Changes(), oauth_token: new UIEventSource(OsmConnectionSpec._osm_token)