forked from MapComplete/MapComplete
Refactoring: simplify title handler
This commit is contained in:
parent
0be7c64ea1
commit
37c523ebf4
2 changed files with 15 additions and 23 deletions
|
@ -1,27 +1,22 @@
|
||||||
import { Store, UIEventSource } from "../UIEventSource"
|
import { Store } from "../UIEventSource"
|
||||||
import Locale from "../../UI/i18n/Locale"
|
import Locale from "../../UI/i18n/Locale"
|
||||||
import Combine from "../../UI/Base/Combine"
|
|
||||||
import { Utils } from "../../Utils"
|
import { Utils } from "../../Utils"
|
||||||
import LayerConfig from "../../Models/ThemeConfig/LayerConfig"
|
|
||||||
import { Feature } from "geojson"
|
import { Feature } from "geojson"
|
||||||
import FeaturePropertiesStore from "../FeatureSource/Actors/FeaturePropertiesStore"
|
|
||||||
import SvelteUIElement from "../../UI/Base/SvelteUIElement"
|
|
||||||
import TagRenderingAnswer from "../../UI/Popup/TagRendering/TagRenderingAnswer.svelte"
|
|
||||||
import { SpecialVisualizationState } from "../../UI/SpecialVisualization"
|
import { SpecialVisualizationState } from "../../UI/SpecialVisualization"
|
||||||
|
|
||||||
export default class TitleHandler {
|
export default class TitleHandler {
|
||||||
constructor(
|
constructor(
|
||||||
selectedElement: Store<Feature>,
|
selectedElement: Store<Feature>,
|
||||||
allElements: FeaturePropertiesStore,
|
|
||||||
state: SpecialVisualizationState
|
state: SpecialVisualizationState
|
||||||
) {
|
) {
|
||||||
const currentTitle: Store<string> = selectedElement.map(
|
const currentTitle: Store<string> = selectedElement.map(
|
||||||
(selected) => {
|
(selected) => {
|
||||||
const defaultTitle = state.layout?.title?.txt ?? "MapComplete"
|
const lng = Locale.language.data
|
||||||
|
const defaultTitle = state.layout?.title?.textFor(lng) ?? "MapComplete"
|
||||||
if (selected === undefined) {
|
if (selected === undefined) {
|
||||||
return defaultTitle
|
return defaultTitle
|
||||||
}
|
}
|
||||||
const layer = state.getMatchingLayer(selected.properties)
|
const layer = state.layout.getMatchingLayer(selected.properties)
|
||||||
if (layer === undefined) {
|
if (layer === undefined) {
|
||||||
return defaultTitle
|
return defaultTitle
|
||||||
}
|
}
|
||||||
|
@ -30,19 +25,16 @@ export default class TitleHandler {
|
||||||
if (layer.title === undefined) {
|
if (layer.title === undefined) {
|
||||||
return defaultTitle
|
return defaultTitle
|
||||||
}
|
}
|
||||||
const tagsSource =
|
const toRender = Utils.NoNull(layer?.title?.GetRenderValues(tags))
|
||||||
allElements.getStore(tags.id) ?? new UIEventSource<Record<string, string>>(tags)
|
const titleUnsubbed = toRender[0]?.then?.textFor(lng)
|
||||||
const title = new SvelteUIElement(TagRenderingAnswer, {
|
if (titleUnsubbed === undefined) {
|
||||||
tags: tagsSource,
|
return defaultTitle
|
||||||
state,
|
}
|
||||||
config: layer.title,
|
const title = Utils.SubstituteKeys(titleUnsubbed, tags)
|
||||||
selectedElement: selectedElement.data,
|
const el = document.createElement("span")
|
||||||
layer,
|
el.innerHTML = title
|
||||||
})
|
return el.innerText + " | " + defaultTitle
|
||||||
return (
|
|
||||||
new Combine([defaultTitle, " | ", title]).ConstructElement()?.textContent ??
|
|
||||||
defaultTitle
|
|
||||||
)
|
|
||||||
},
|
},
|
||||||
[Locale.language]
|
[Locale.language]
|
||||||
)
|
)
|
||||||
|
|
|
@ -954,7 +954,7 @@ export default class ThemeViewState implements SpecialVisualizationState {
|
||||||
})
|
})
|
||||||
new ThemeViewStateHashActor(this)
|
new ThemeViewStateHashActor(this)
|
||||||
new MetaTagging(this)
|
new MetaTagging(this)
|
||||||
new TitleHandler(this.selectedElement, this.featureProperties, this)
|
new TitleHandler(this.selectedElement, this)
|
||||||
new ChangeToElementsActor(this.changes, this.featureProperties)
|
new ChangeToElementsActor(this.changes, this.featureProperties)
|
||||||
new PendingChangesUploader(this.changes, this.selectedElement, this.imageUploadManager)
|
new PendingChangesUploader(this.changes, this.selectedElement, this.imageUploadManager)
|
||||||
new SelectedElementTagsUpdater(this)
|
new SelectedElementTagsUpdater(this)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue