From d7b83e0d880c42c8d23ea8b3347e45698a28fb4c Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Mon, 28 Jul 2025 01:17:12 +0200 Subject: [PATCH] Refactoring: cleanup of no longer necessary code --- src/Logic/DetermineTheme.ts | 4 -- src/UI/Base/Combine.ts | 4 -- src/UI/Base/SvelteUIElement.ts | 5 --- src/UI/BaseUIElement.ts | 26 ----------- src/UI/Popup/DataVisualisations.ts | 44 ------------------- .../Popup/ImportButtons/WayImportButtonViz.ts | 4 +- src/UI/i18n/Translations.ts | 28 +----------- src/index.ts | 2 + 8 files changed, 4 insertions(+), 113 deletions(-) diff --git a/src/Logic/DetermineTheme.ts b/src/Logic/DetermineTheme.ts index 584317db1..26a69145a 100644 --- a/src/Logic/DetermineTheme.ts +++ b/src/Logic/DetermineTheme.ts @@ -208,10 +208,6 @@ export default class DetermineTheme { private static async LoadRemoteTheme(link: string): Promise { console.log("Downloading map theme from ", link) - new FixedUiElement(`Downloading the theme from the link...`).AttachTo( - "maindiv" - ) - let parsed = await Utils.downloadJson(link) let forcedId = parsed.id const url = new URL(link) diff --git a/src/UI/Base/Combine.ts b/src/UI/Base/Combine.ts index 44c904944..5d9f80712 100644 --- a/src/UI/Base/Combine.ts +++ b/src/UI/Base/Combine.ts @@ -25,10 +25,6 @@ export default class Combine extends BaseUIElement { } } - public getElements(): BaseUIElement[] { - return this.uiElements - } - protected InnerConstructElement(): HTMLElement { const el = document.createElement("span") try { diff --git a/src/UI/Base/SvelteUIElement.ts b/src/UI/Base/SvelteUIElement.ts index aba7386c6..fcb8d0e2c 100644 --- a/src/UI/Base/SvelteUIElement.ts +++ b/src/UI/Base/SvelteUIElement.ts @@ -45,11 +45,6 @@ export default class SvelteUIElement< this._slots = slots } - public setSpan() { - this.tag = "span" - return this - } - protected InnerConstructElement(): HTMLElement { const el = document.createElement(this.tag) new this._svelteComponent({ diff --git a/src/UI/BaseUIElement.ts b/src/UI/BaseUIElement.ts index aef860aa1..c5539a630 100644 --- a/src/UI/BaseUIElement.ts +++ b/src/UI/BaseUIElement.ts @@ -13,33 +13,7 @@ export default abstract class BaseUIElement { protected readonly clss: Set = new Set() protected style: string private _onClick: () => void | Promise - AttachTo(divId: string) { - const element = document.getElementById(divId) - if (element === null) { - if (Utils.runningFromConsole) { - this.ConstructElement() - return - } - throw "SEVERE: could not attach UIElement to " + divId - } - let alreadyThere = false - const elementToAdd = this.ConstructElement() - const childs = Array.from(element.childNodes) - for (const child of childs) { - if (child === elementToAdd) { - alreadyThere = true - continue - } - element.removeChild(child) - } - - if (elementToAdd !== undefined && !alreadyThere) { - element.appendChild(elementToAdd) - } - - return this - } /** * Adds all the relevant classes, space separated */ diff --git a/src/UI/Popup/DataVisualisations.ts b/src/UI/Popup/DataVisualisations.ts index a643209bf..0f7987055 100644 --- a/src/UI/Popup/DataVisualisations.ts +++ b/src/UI/Popup/DataVisualisations.ts @@ -22,8 +22,6 @@ import { And } from "../../Logic/Tags/And" import TagRenderingConfig from "../../Models/ThemeConfig/TagRenderingConfig" import TagRenderingEditable from "./TagRendering/TagRenderingEditable.svelte" import AllTagsPanel from "./AllTagsPanel/AllTagsPanel.svelte" -import { FixedUiElement } from "../Base/FixedUiElement" -import { TagUtils } from "../../Logic/Tags/TagUtils" import CollectionTimes from "../CollectionTimes/CollectionTimes.svelte" class DirectionIndicatorVis extends SpecialVisualization { @@ -293,47 +291,6 @@ class AllTagsVis extends SpecialVisualizationSvelte { } } -class TagsVis extends SpecialVisualization { - funcName = "tags" - docs = "Shows a (json of) tags in a human-readable way + links to the wiki" - - args = [ - { - name: "key", - type: "key", - defaultValue: "value", - doc: "The key to look for the tags", - }, - ] - - constr( - state: SpecialVisualizationState, - tagSource: UIEventSource>, - argument: string[], - ): BaseUIElement { - const key = argument[0] ?? "value" - return new VariableUiElement( - tagSource.map((tags) => { - let value = tags[key] - if (!value) { - return new FixedUiElement("No tags found").SetClass("font-bold") - } - if (typeof value === "string" && value.startsWith("{")) { - value = JSON.parse(value) - } - try { - const parsed = TagUtils.Tag(value) - return parsed.asHumanString(true, false, {}) - } catch (e) { - return new FixedUiElement( - "Could not parse this tag: " + JSON.stringify(value) + " due to " + e, - ).SetClass("alert") - } - }), - ) - } -} - class PointsInTimeVis extends SpecialVisualization { docs = "Creates a visualisation for 'points in time', e.g. collection times of a postbox" group = "data" @@ -372,7 +329,6 @@ export class DataVisualisations { new PresetDescription(), new PresetTypeSelect(), new AllTagsVis(), - new TagsVis(), ] } } diff --git a/src/UI/Popup/ImportButtons/WayImportButtonViz.ts b/src/UI/Popup/ImportButtons/WayImportButtonViz.ts index 4a061fef6..61272532f 100644 --- a/src/UI/Popup/ImportButtons/WayImportButtonViz.ts +++ b/src/UI/Popup/ImportButtons/WayImportButtonViz.ts @@ -6,7 +6,6 @@ import BaseUIElement from "../../BaseUIElement" import { ImportFlowUtils } from "./ImportFlow" import LayerConfig from "../../../Models/ThemeConfig/LayerConfig" import SvelteUIElement from "../../Base/SvelteUIElement" -import { FixedUiElement } from "../../Base/FixedUiElement" import WayImportFlow from "./WayImportFlow.svelte" import WayImportFlowState, { WayImportFlowArguments } from "./WayImportFlowState" import { Utils } from "../../../Utils" @@ -70,8 +69,7 @@ export default class WayImportButtonViz extends SpecialVisualization implements ): BaseUIElement { const geometry = feature.geometry if (!(geometry.type == "LineString" || geometry.type === "Polygon")) { - console.error("Invalid type to import", geometry.type) - return new FixedUiElement("Invalid geometry type:" + geometry.type).SetClass("alert") + throw "Invalid type to import " + geometry.type } const args: WayImportFlowArguments = Utils.ParseVisArgs(this.args, argument) const tagsToApply = ImportFlowUtils.getTagsToApply(tagSource, args) diff --git a/src/UI/i18n/Translations.ts b/src/UI/i18n/Translations.ts index 3d8515615..0ab0408ba 100644 --- a/src/UI/i18n/Translations.ts +++ b/src/UI/i18n/Translations.ts @@ -1,6 +1,4 @@ -import { FixedUiElement } from "../Base/FixedUiElement" import { Translation, TypedTranslation } from "./Translation" -import BaseUIElement from "../BaseUIElement" import CompiledTranslations from "../../assets/generated/CompiledTranslations" import LanguageUtils from "../../Utils/LanguageUtils" import { Store } from "../../Logic/UIEventSource" @@ -12,31 +10,7 @@ export default class Translations { static readonly t: Readonly = CompiledTranslations.t private static knownLanguages = LanguageUtils.usedLanguages - constructor() { - throw "Translations is static. If you want to intitialize a new translation, use the singular form" - } - - /** - * @deprecated - */ - public static W(s: string | number | boolean | BaseUIElement): BaseUIElement { - if (typeof s === "string") { - return new FixedUiElement(s) - } - if (typeof s === "number") { - return new FixedUiElement("" + s).SetClass("font-bold") - } - if (typeof s === "boolean") { - return new FixedUiElement("" + s).SetClass("font-bold") - } - if (typeof s === "object") { - if (s.ConstructElement) { - return s - } - const v = JSON.stringify(s) - return new FixedUiElement(v).SetClass("literal-code") - } - return s + private constructor() { } /** diff --git a/src/index.ts b/src/index.ts index 87a53dee3..462d8fa9c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -11,6 +11,8 @@ async function main() { console.error("Huh? Couldn't remove child!") } try { + + document.getElementById("maindiv").innerHTML = "
Loading map...
" const theme = await DetermineTheme.getTheme() new SingleThemeGui({ target,