From 4525a9d5ed08a959debdfe9301983f7dd1badebd Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Wed, 22 Jan 2025 02:27:26 +0100 Subject: [PATCH 1/2] Chore: small refactorings --- src/UI/StatisticsGUI.ts | 5 +++-- src/index.ts | 1 - 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/UI/StatisticsGUI.ts b/src/UI/StatisticsGUI.ts index 90a3674e8..f3e659134 100644 --- a/src/UI/StatisticsGUI.ts +++ b/src/UI/StatisticsGUI.ts @@ -1,4 +1,5 @@ -import SvelteUIElement from "./Base/SvelteUIElement" import { default as StatisticsSvelte } from "../UI/Statistics/StatisticsGui.svelte" -new SvelteUIElement(StatisticsSvelte).AttachTo("main") +const target = document.getElementById("main") +target.innerHTML = "" +new StatisticsSvelte({ target }) diff --git a/src/index.ts b/src/index.ts index c5013c067..b74554698 100644 --- a/src/index.ts +++ b/src/index.ts @@ -52,7 +52,6 @@ async function main() { DetermineTheme.getTheme(), await getAvailableLayers(), ]) - availableLayers?.delete("cycle_highways") // TODO remove after next cache.mapcomplete.org update console.log("The available layers on server are", Array.from(availableLayers)) const state = new ThemeViewState(theme, availableLayers) const target = document.getElementById("maindiv") From 09109925bc295130e669ccaec6768957220bd656 Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Wed, 22 Jan 2025 02:39:28 +0100 Subject: [PATCH 2/2] Fix: don't open login page upon first visit of MapComplete --- src/Logic/Osm/OsmConnection.ts | 12 +++++------- src/Logic/Osm/OsmPreferences.ts | 10 ++++++++-- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/Logic/Osm/OsmConnection.ts b/src/Logic/Osm/OsmConnection.ts index bffd61bf5..2caa69b6c 100644 --- a/src/Logic/Osm/OsmConnection.ts +++ b/src/Logic/Osm/OsmConnection.ts @@ -103,7 +103,7 @@ export class OsmConnection { oauth_token?: UIEventSource // Used to keep multiple changesets open and to write to the correct changeset singlePage?: boolean - attemptLogin?: true | boolean + attemptLogin?: boolean /** * If true: automatically check if we're still online every 5 minutes + fetch messages */ @@ -152,7 +152,7 @@ export class OsmConnection { this._dryRun = options.dryRun ?? new UIEventSource(false) - this.updateAuthObject() + this.updateAuthObject(false) if (!this.fakeUser) { this.CheckForMessagesContinuously() } @@ -230,9 +230,7 @@ export class OsmConnection { console.log("AttemptLogin called, but ignored as fakeUser is set") return } - - console.log("Trying to log in...") - this.updateAuthObject() + this.updateAuthObject(true) LocalStorageSource.get("location_before_login").setData( Utils.runningFromConsole ? undefined : window.location.href @@ -553,7 +551,7 @@ export class OsmConnection { }) } - private updateAuthObject() { + private updateAuthObject(autoLogin: boolean) { this.auth = new osmAuth({ client_id: this._oauth_config.oauth_client_id, url: this._oauth_config.url, @@ -565,7 +563,7 @@ export class OsmConnection { * However, this breaks in iframes so we open a popup in that case */ singlepage: !this._iframeMode, - auto: true, + auto: autoLogin, apiUrl: this._oauth_config.api_url ?? this._oauth_config.url, }) } diff --git a/src/Logic/Osm/OsmPreferences.ts b/src/Logic/Osm/OsmPreferences.ts index 374b55b0d..f89dd65d5 100644 --- a/src/Logic/Osm/OsmPreferences.ts +++ b/src/Logic/Osm/OsmPreferences.ts @@ -209,7 +209,10 @@ export class OsmPreferences { * Bulk-downloads all preferences * @private */ - private getPreferencesDictDirectly(): Promise> { + private async getPreferencesDictDirectly(): Promise> { + if(!this.osmConnection.isLoggedIn.data){ + return {} + } return new Promise>((resolve, reject) => { this.auth.xhr( { @@ -257,6 +260,9 @@ export class OsmPreferences { * */ private async uploadKvSplit(k: string, v: string) { + if(!this.osmConnection.isLoggedIn.data){ + return + } if (v === null || v === undefined || v === "" || v === "undefined" || v === "null") { const keysToDelete = OsmPreferences.keysStartingWith(this.seenKeys, k) await Promise.all(keysToDelete.map((k) => this.deleteKeyDirectly(k))) @@ -280,7 +286,7 @@ export class OsmPreferences { */ private deleteKeyDirectly(k: string) { if (!this.osmConnection.isLoggedIn.data) { - console.debug(`Not saving preference ${k}: user not logged in`) + console.debug(`Not deleting preference ${k}: user not logged in`) return }