2021-01-08 18:02:07 +01:00
|
|
|
import {UIEventSource} from "../UIEventSource";
|
|
|
|
import Translations from "../../UI/i18n/Translations";
|
|
|
|
import Locale from "../../UI/i18n/Locale";
|
2021-01-25 03:12:09 +01:00
|
|
|
import TagRenderingAnswer from "../../UI/Popup/TagRenderingAnswer";
|
|
|
|
import Combine from "../../UI/Base/Combine";
|
2021-09-28 18:00:44 +02:00
|
|
|
import LayoutConfig from "../../Models/ThemeConfig/LayoutConfig";
|
|
|
|
import {ElementStorage} from "../ElementStorage";
|
2021-10-20 00:09:40 +02:00
|
|
|
import {Utils} from "../../Utils";
|
2021-01-08 18:02:07 +01:00
|
|
|
|
2021-09-22 05:02:09 +02:00
|
|
|
export default class TitleHandler {
|
2021-09-28 18:00:44 +02:00
|
|
|
constructor(state : {
|
|
|
|
selectedElement: UIEventSource<any>,
|
|
|
|
layoutToUse: LayoutConfig,
|
|
|
|
allElements: ElementStorage
|
|
|
|
}) {
|
2021-09-22 05:02:09 +02:00
|
|
|
const currentTitle: UIEventSource<string> = state.selectedElement.map(
|
|
|
|
selected => {
|
2021-09-28 18:00:44 +02:00
|
|
|
const layout = state.layoutToUse
|
2021-09-22 05:02:09 +02:00
|
|
|
const defaultTitle = Translations.WT(layout?.title)?.txt ?? "MapComplete"
|
2021-09-09 00:05:51 +02:00
|
|
|
|
2021-09-22 05:02:09 +02:00
|
|
|
if (selected === undefined) {
|
|
|
|
return defaultTitle
|
|
|
|
}
|
2021-03-21 02:03:07 +01:00
|
|
|
|
2021-09-22 05:02:09 +02:00
|
|
|
const tags = selected.properties;
|
|
|
|
for (const layer of layout.layers) {
|
|
|
|
if (layer.title === undefined) {
|
|
|
|
continue;
|
2021-06-11 22:51:45 +02:00
|
|
|
}
|
2021-09-22 05:02:09 +02:00
|
|
|
if (layer.source.osmTags.matchesProperties(tags)) {
|
|
|
|
const tagsSource = state.allElements.getEventSourceById(tags.id)
|
|
|
|
const title = new TagRenderingAnswer(tagsSource, layer.title)
|
2021-09-29 01:12:38 +02:00
|
|
|
return new Combine([defaultTitle, " | ", title]).ConstructElement()?.innerText ?? defaultTitle;
|
2021-06-11 22:51:45 +02:00
|
|
|
}
|
2021-04-17 23:36:46 +02:00
|
|
|
}
|
2021-09-22 05:02:09 +02:00
|
|
|
return defaultTitle
|
2021-09-28 18:00:44 +02:00
|
|
|
}, [Locale.language]
|
2021-06-11 22:51:45 +02:00
|
|
|
)
|
2021-09-09 00:05:51 +02:00
|
|
|
|
|
|
|
|
2021-09-22 05:02:09 +02:00
|
|
|
currentTitle.addCallbackAndRunD(title => {
|
2021-10-20 00:09:40 +02:00
|
|
|
if(Utils.runningFromConsole){
|
|
|
|
return
|
|
|
|
}
|
2021-06-11 22:51:45 +02:00
|
|
|
document.title = title
|
2021-03-21 02:03:07 +01:00
|
|
|
})
|
2021-01-08 18:02:07 +01:00
|
|
|
}
|
|
|
|
}
|