From 2606a27f60605538813eb82f390f0dd64e6a5c35 Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Sun, 21 Mar 2021 02:03:07 +0100 Subject: [PATCH] Fix page title rendering --- Logic/Actors/TitleHandler.ts | 45 +++++++++++++++++++----------------- Models/Constants.ts | 2 +- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/Logic/Actors/TitleHandler.ts b/Logic/Actors/TitleHandler.ts index c31cff8fc..aa7309487 100644 --- a/Logic/Actors/TitleHandler.ts +++ b/Logic/Actors/TitleHandler.ts @@ -11,62 +11,65 @@ class TitleElement extends UIElement { private readonly _layoutToUse: UIEventSource; private readonly _selectedFeature: UIEventSource; private readonly _allElementsStorage: ElementStorage; - + constructor(layoutToUse: UIEventSource, selectedFeature: UIEventSource, - allElementsStorage : ElementStorage) { + allElementsStorage: ElementStorage) { super(layoutToUse); this._layoutToUse = layoutToUse; this._selectedFeature = selectedFeature; this._allElementsStorage = allElementsStorage; this.ListenTo(Locale.language); + this.ListenTo(this._selectedFeature) this.dumbMode = false; } - + InnerRender(): string { - + const defaultTitle = Translations.WT(this._layoutToUse.data?.title)?.txt ?? "MapComplete" + console.log("Default title: ", defaultTitle) const feature = this._selectedFeature.data; - if(feature === undefined){ + if (feature === undefined) { return defaultTitle; } const layout = this._layoutToUse.data; const properties = this._selectedFeature.data.properties; - for (const layer of layout.layers) { - if(layer.title === undefined){ - continue; - } + for (const layer of layout.layers) { + if (layer.title === undefined) { + continue; + } if (layer.overpassTags.matchesProperties(properties)) { const title = new TagRenderingAnswer( this._allElementsStorage.getEventSourceFor(feature), layer.title ) - return new Combine([defaultTitle," | ", title]).Render(); + return new Combine([defaultTitle, " | ", title]).Render(); } } return defaultTitle; } - + } export default class TitleHandler { constructor(layoutToUse: UIEventSource, selectedFeature: UIEventSource, - allElementsStorage : ElementStorage) { + allElementsStorage: ElementStorage) { - new TitleElement(layoutToUse, selectedFeature, allElementsStorage) - .addCallbackAndRun(contents => { + console.log("Titlehandler inited") + selectedFeature.addCallbackAndRun(_ => { + const title = new TitleElement(layoutToUse, selectedFeature, allElementsStorage) + const d = document.createElement('div'); + const contents = title.InnerRender() + d.innerHTML = contents; + console.log("Setting title to ", d.innerText, contents) + // We pass everything into a div to strip out images etc... + document.title = (d.textContent || d.innerText); + }) - const d = document.createElement('div'); - d.innerHTML = contents; - // We pass everything into a div to strip out images etc... - document.title = (d.textContent || d.innerText); - - }); - } } \ No newline at end of file diff --git a/Models/Constants.ts b/Models/Constants.ts index f56372826..c97bb0375 100644 --- a/Models/Constants.ts +++ b/Models/Constants.ts @@ -2,7 +2,7 @@ import { Utils } from "../Utils"; export default class Constants { - public static vNumber = "0.5.14"; + public static vNumber = "0.5.15"; // The user journey states thresholds when a new feature gets unlocked public static userJourney = {