Chore: housekeeping, linting

This commit is contained in:
Pieter Vander Vennet 2025-06-04 00:21:28 +02:00
parent f942529755
commit 30d00eb06d
74 changed files with 998 additions and 623 deletions

View file

@ -20,16 +20,13 @@
export let ids: Store<string[] | undefined>
export let state: SpecialVisualizationState
export let options: {
target_layer_id: string,
targetTagRendering: string,
text: string,
icon: string,
target_layer_id: string
targetTagRendering: string
text: string
icon: string
}
let buttonState: UIEventSource<
"idle" | "running" | "done" | { error: string }
> = new UIEventSource<
"idle" | "running" | "done" | { error: string }
>("idle")
let buttonState: UIEventSource<"idle" | "running" | "done" | { error: string }> =
new UIEventSource<"idle" | "running" | "done" | { error: string }>("idle")
let tagRenderingConfig: TagRenderingConfig
let appliedNumberOfFeatures = new UIEventSource<number>(0)
@ -40,23 +37,22 @@
const mlmap = new UIEventSource(undefined)
const mla = new MapLibreAdaptor(mlmap, {
rasterLayer: state.mapProperties.rasterLayer
rasterLayer: state.mapProperties.rasterLayer,
})
mla.allowZooming.setData(false)
mla.allowMoving.setData(false)
const features = ids.mapD(ids => ids.map((id) =>
state.indexedFeatures.featuresById.data.get(id)
))
const features = ids.mapD((ids) =>
ids.map((id) => state.indexedFeatures.featuresById.data.get(id))
)
new ShowDataLayer(mlmap, {
features: StaticFeatureSource.fromGeojson(features),
zoomToFeatures: true,
layer: layer.layerDef
layer: layer.layerDef,
})
features.addCallbackAndRunD(f => console.log("Features are now", f))
features.addCallbackAndRunD((f) => console.log("Features are now", f))
async function applyAllChanges() {
buttonState.set("running")
@ -77,8 +73,8 @@
if (specialRenderings.length == 0) {
console.warn(
"AutoApply: feature " +
targetFeatureId +
" got a rendering without supported auto actions:",
targetFeatureId +
" got a rendering without supported auto actions:",
rendering
)
}
@ -88,12 +84,7 @@
continue
}
const action = <AutoAction>specialRendering.func
await action.applyActionOn(
feature,
state,
featureTags,
specialRendering.args
)
await action.applyActionOn(feature, state, featureTags, specialRendering.args)
}
appliedOn.push(targetFeatureId)
if (i % 50 === 0) {
@ -117,13 +108,13 @@
}
const t = Translations.t.general.add.import
</script>
{#if !state.theme.official && !state.featureSwitchIsTesting.data}
<div class="alert">The auto-apply button is only available in official themes (or in testing mode)</div>
<div class="alert">
The auto-apply button is only available in official themes (or in testing mode)
</div>
<Tr t={t.howToTest} />
{:else if ids === undefined}
<Loading>Gathering which elements support auto-apply...</Loading>
{:else if tagRenderingConfig === undefined}
@ -132,7 +123,6 @@
<div>No elements found to perform action</div>
{:else if $buttonState.error !== undefined}
<div class="flex flex-col">
<div class="alert">Something went wrong</div>
<div>{$buttonState.error}</div>
</div>
@ -144,7 +134,11 @@
</Loading>
{:else if $buttonState === "idle"}
<div class="flex flex-col">
<button on:click={() => {applyAllChanges()}}>
<button
on:click={() => {
applyAllChanges()
}}
>
<img class="h-8 w-8" alt="" src={options.icon} />
{options.text}
</button>
@ -156,7 +150,6 @@
<div class="subtle link-underline">
The following objects will be updated:
<div class="flex flex-wrap gap-x-2">
{#each $ids as featId}
{#if layer.layerDef.source.geojsonSource === undefined}
<a href={"https://openstreetmap.org/" + featId} target="_blank">{featId}</a>
@ -172,8 +165,3 @@
{:else}
<div>Not supposed to show this... AutoApplyButton has invalid buttonstate: {$buttonState}</div>
{/if}

View file

@ -1,7 +1,11 @@
import { Store, Stores, UIEventSource } from "../../Logic/UIEventSource"
import ThemeConfig from "../../Models/ThemeConfig/ThemeConfig"
import { Changes } from "../../Logic/Osm/Changes"
import { SpecialVisualization, SpecialVisualizationState, SpecialVisualizationSvelte } from "../SpecialVisualization"
import {
SpecialVisualization,
SpecialVisualizationState,
SpecialVisualizationSvelte,
} from "../SpecialVisualization"
import { IndexedFeatureSource } from "../../Logic/FeatureSource/FeatureSource"
import SvelteUIElement from "../Base/SvelteUIElement"
import { Feature } from "geojson"
@ -94,26 +98,28 @@ export default class AutoApplyButtonVis implements SpecialVisualizationSvelte {
target_layer_id,
targetTagRendering,
text,
icon
icon,
}
const to_parse: UIEventSource<string[]> = new UIEventSource<string[]>(undefined)
Stores.Chronic(500, () => to_parse.data === undefined).map(() => {
const applicable = <string | string[]>tagSource.data[argument[1]]
if (typeof applicable === "string") {
return <string[]>JSON.parse(applicable)
} else {
return applicable
}
}).addCallbackAndRunD(data => {
to_parse.set(data)
})
Stores.Chronic(500, () => to_parse.data === undefined)
.map(() => {
const applicable = <string | string[]>tagSource.data[argument[1]]
if (typeof applicable === "string") {
return <string[]>JSON.parse(applicable)
} else {
return applicable
}
})
.addCallbackAndRunD((data) => {
to_parse.set(data)
})
const stableIds: Store<string[]> = Stores.ListStabilized(to_parse).map((ids) => {
if (typeof ids === "string") {
ids = JSON.parse(ids)
}
return ids.map(id => id)
return ids.map((id) => id)
})
return new SvelteUIElement(AutoApplyButton, { state, ids: stableIds, options })
}

View file

@ -39,16 +39,20 @@
console.log(key, "-->", extraUrlParams[key])
params.push(key + "=" + encodeURIComponent(extraUrlParams[key]))
}
let url = id.map((id) => {
if (id) {
return "#" + id
} else {
return ""
}
}).map(
(id) =>
`${window.location.protocol}//${window.location.host}${window.location.pathname}?${params.join("&")}${id}`
)
let url = id
.map((id) => {
if (id) {
return "#" + id
} else {
return ""
}
})
.map(
(id) =>
`${window.location.protocol}//${window.location.host}${
window.location.pathname
}?${params.join("&")}${id}`
)
function toggleSize() {
if (size.data !== bigSize) {
@ -58,26 +62,27 @@
}
}
let sideTextSub = (tags ?? new ImmutableStore({})).map(tgs => Utils.SubstituteKeys(sideText, tgs))
let sideTextSub = (tags ?? new ImmutableStore({})).map((tgs) =>
Utils.SubstituteKeys(sideText, tgs)
)
</script>
{#if $id?.startsWith("node/-")}
<!-- Not yet uploaded, doesn't have a fixed ID -->
<Loading />
{:else}
<div class="flex flex-col my-4">
<div class="flex w-full items-center ">
<img
class="shrink-0"
on:click={() => toggleSize()}
src={new Qr($url).toImageElement($size)}
style={`width: ${$size}px; height: ${$size}px`}
/>
{#if sideText}
<div class={sideTextClass}>{ $sideTextSub}</div>
{/if}
<div class="my-4 flex flex-col">
<div class="flex w-full items-center">
<img
class="shrink-0"
on:click={() => toggleSize()}
src={new Qr($url).toImageElement($size)}
style={`width: ${$size}px; height: ${$size}px`}
/>
{#if sideText}
<div class={sideTextClass}>{$sideTextSub}</div>
{/if}
</div>
<a href={$url} target="_blank" class="subtle text-sm ">{$url}</a>
<a href={$url} target="_blank" class="subtle text-sm">{$url}</a>
</div>
{/if}