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 Combine from "../../UI/Base/Combine" | ||||
| import { Utils } from "../../Utils" | ||||
| import LayerConfig from "../../Models/ThemeConfig/LayerConfig" | ||||
| 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" | ||||
| 
 | ||||
| export default class TitleHandler { | ||||
|     constructor( | ||||
|         selectedElement: Store<Feature>, | ||||
|         allElements: FeaturePropertiesStore, | ||||
|         state: SpecialVisualizationState | ||||
|     ) { | ||||
|         const currentTitle: Store<string> = selectedElement.map( | ||||
|             (selected) => { | ||||
|                 const defaultTitle = state.layout?.title?.txt ?? "MapComplete" | ||||
|                 const lng = Locale.language.data | ||||
|                 const defaultTitle = state.layout?.title?.textFor(lng) ?? "MapComplete" | ||||
|                 if (selected === undefined) { | ||||
|                     return defaultTitle | ||||
|                 } | ||||
|                 const layer = state.getMatchingLayer(selected.properties) | ||||
|                 const layer = state.layout.getMatchingLayer(selected.properties) | ||||
|                 if (layer === undefined) { | ||||
|                     return defaultTitle | ||||
|                 } | ||||
|  | @ -30,19 +25,16 @@ export default class TitleHandler { | |||
|                 if (layer.title === undefined) { | ||||
|                     return defaultTitle | ||||
|                 } | ||||
|                 const tagsSource = | ||||
|                     allElements.getStore(tags.id) ?? new UIEventSource<Record<string, string>>(tags) | ||||
|                 const title = new SvelteUIElement(TagRenderingAnswer, { | ||||
|                     tags: tagsSource, | ||||
|                     state, | ||||
|                     config: layer.title, | ||||
|                     selectedElement: selectedElement.data, | ||||
|                     layer, | ||||
|                 }) | ||||
|                 return ( | ||||
|                     new Combine([defaultTitle, " | ", title]).ConstructElement()?.textContent ?? | ||||
|                     defaultTitle | ||||
|                 ) | ||||
|                 const toRender = Utils.NoNull(layer?.title?.GetRenderValues(tags)) | ||||
|                 const titleUnsubbed = toRender[0]?.then?.textFor(lng) | ||||
|                 if (titleUnsubbed === undefined) { | ||||
|                     return defaultTitle | ||||
|                 } | ||||
|                 const title = Utils.SubstituteKeys(titleUnsubbed, tags) | ||||
|                 const el = document.createElement("span") | ||||
|                 el.innerHTML = title | ||||
|                 return el.innerText + " | " + defaultTitle | ||||
| 
 | ||||
|             }, | ||||
|             [Locale.language] | ||||
|         ) | ||||
|  |  | |||
|  | @ -954,7 +954,7 @@ export default class ThemeViewState implements SpecialVisualizationState { | |||
|         }) | ||||
|         new ThemeViewStateHashActor(this) | ||||
|         new MetaTagging(this) | ||||
|         new TitleHandler(this.selectedElement, this.featureProperties, this) | ||||
|         new TitleHandler(this.selectedElement, this) | ||||
|         new ChangeToElementsActor(this.changes, this.featureProperties) | ||||
|         new PendingChangesUploader(this.changes, this.selectedElement, this.imageUploadManager) | ||||
|         new SelectedElementTagsUpdater(this) | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue