From 1e0a1fdf97ccab0154dfff95482606c7ec2f5f03 Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Sun, 18 Oct 2020 00:28:51 +0200 Subject: [PATCH] Fix morescreen (which shows the custom themes now), remove invalid themes automatically --- InitUiElements.ts | 7 +------ Logic/Osm/OsmPreferences.ts | 15 +++++++++++++-- State.ts | 11 ++++++++++- UI/Base/TabbedComponent.ts | 2 +- UI/MoreScreen.ts | 7 ++++++- 5 files changed, 31 insertions(+), 11 deletions(-) diff --git a/InitUiElements.ts b/InitUiElements.ts index 7c5a2ea..729b509 100644 --- a/InitUiElements.ts +++ b/InitUiElements.ts @@ -282,12 +282,7 @@ export class InitUiElements { tabs.push({ header: ``, - content: new VariableUiElement(State.state.osmConnection.userDetails.map(userdetails => { - if(userdetails.csCount < State.userJourney.moreScreenUnlock){ - return ""; - } - return new MoreScreen().Render() - }, [Locale.language])) + content: new MoreScreen() }); } diff --git a/Logic/Osm/OsmPreferences.ts b/Logic/Osm/OsmPreferences.ts index 8ff413a..7a00639 100644 --- a/Logic/Osm/OsmPreferences.ts +++ b/Logic/Osm/OsmPreferences.ts @@ -41,7 +41,19 @@ export class OsmPreferences { const self = this; source.addCallback(str => { if (str === undefined || str === "") { - return + return; + } + if(str === null){ + console.error("Deleting "+allStartWith); + let count = parseInt(length.data); + for (let i = 0; i < count; i++) { + // Delete all the preferences + self.GetPreference(allStartWith + "-" + i, "") + .setData(""); + } + self.GetPreference(allStartWith + "-length", "") + .setData(""); + return } let i = 0; @@ -75,7 +87,6 @@ export class OsmPreferences { } source.setData(str); - console.log("Long preference", key, "has", str.length, "chars"); } length.addCallback(l => { diff --git a/State.ts b/State.ts index 0d5e8c3..bbe2f57 100644 --- a/State.ts +++ b/State.ts @@ -205,6 +205,7 @@ export default class State { if (allPreferences === undefined) { return installedThemes; } + const invalidThemes = [] for (const allPreferencesKey in allPreferences) { const themename = allPreferencesKey.match(/^mapcomplete-installed-theme-(.*)-combined-length$/); if (themename && themename[1] !== "") { @@ -226,11 +227,19 @@ export default class State { definition: customLayout.data }); } catch (e) { - console.warn("Could not parse custom layout from preferences: ", allPreferencesKey, e, customLayout.data); + console.warn("Could not parse custom layout from preferences - deleting: ", allPreferencesKey, e, customLayout.data); + invalidThemes.push(themename[1]) } } } + for (const invalid of invalidThemes) { + console.error("Attempting to remove ", invalid) + this.osmConnection.GetLongPreference( + "installed-theme-" + invalid + ).setData(null); + } + return installedThemes; }); diff --git a/UI/Base/TabbedComponent.ts b/UI/Base/TabbedComponent.ts index e7204db..a0c36ef 100644 --- a/UI/Base/TabbedComponent.ts +++ b/UI/Base/TabbedComponent.ts @@ -14,7 +14,6 @@ export class TabbedComponent extends UIElement { let element = elements[i]; this.headers.push(Translations.W(element.header).onClick(() => self._source.setData(i))); const content = Translations.W(element.content) - this.ListenTo(content) this.content.push(content); } } @@ -34,6 +33,7 @@ export class TabbedComponent extends UIElement { headerBar = "
" + headerBar + "
" const content = this.content[this._source.data]; + console.log("Rendering tab", this._source.data); return headerBar + "
" + (content?.Render() ?? "") + "
"; } diff --git a/UI/MoreScreen.ts b/UI/MoreScreen.ts index ded3c01..6cab5c0 100644 --- a/UI/MoreScreen.ts +++ b/UI/MoreScreen.ts @@ -12,11 +12,15 @@ import {Layout} from "../Customizations/Layout"; export class MoreScreen extends UIElement { + constructor() { super(State.state.locationControl); this.ListenTo(State.state.osmConnection.userDetails); this.ListenTo(State.state.installedThemes); - + + State.state.installedThemes.addCallback(themes => { + console.log("INSTALLED THEMES COUNT:", themes.length) + }) } private createLinkButton(layout: Layout, customThemeDefinition: string = undefined) { @@ -68,6 +72,7 @@ export class MoreScreen extends UIElement { InnerRender(): string { + console.log("Inner rendering MORE") const tr = Translations.t.general.morescreen; const els: UIElement[] = []