From 34d852771855e8e4d7c2a771cb77907572d12d9f Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Thu, 11 Jan 2024 02:20:57 +0100 Subject: [PATCH] Refactoring: move uploadGPXToOSm into svelte --- assets/layers/gps_track/gps_track.json | 17 +- src/Logic/Actors/GeoLocationHandler.ts | 8 +- src/Logic/Osm/OsmConnection.ts | 8 +- src/UI/Base/SubtleButton.ts | 28 --- .../BigComponents/UploadTraceToOsmUI.svelte | 181 ++++++++++++++++++ src/UI/BigComponents/UploadTraceToOsmUI.ts | 155 --------------- src/UI/Popup/UploadToOsmViz.ts | 10 +- src/UI/ThemeViewGUI.svelte | 3 + src/Utils/selectDefault.ts | 10 + 9 files changed, 222 insertions(+), 198 deletions(-) create mode 100644 src/UI/BigComponents/UploadTraceToOsmUI.svelte delete mode 100644 src/UI/BigComponents/UploadTraceToOsmUI.ts create mode 100644 src/Utils/selectDefault.ts diff --git a/assets/layers/gps_track/gps_track.json b/assets/layers/gps_track/gps_track.json index d3797f616..6a934d223 100644 --- a/assets/layers/gps_track/gps_track.json +++ b/assets/layers/gps_track/gps_track.json @@ -23,7 +23,22 @@ "cs": "Ujetá cesta" } }, - "pointRendering": [], + "pointRendering": [ + { + "location": [ + "start" + ], + "marker": [ + { + "icon": "circle", + "color": "#bb000077" + } + ], + "iconSize": "10,10", + "pitchAlignment": "map", + "rotationAlignment": "map" + } + ], "lineRendering": [ { "width": 3, diff --git a/src/Logic/Actors/GeoLocationHandler.ts b/src/Logic/Actors/GeoLocationHandler.ts index 152b12979..9d32dead4 100644 --- a/src/Logic/Actors/GeoLocationHandler.ts +++ b/src/Logic/Actors/GeoLocationHandler.ts @@ -153,11 +153,7 @@ export default class GeoLocationHandler { const features: UIEventSource = new UIEventSource([]) this.currentUserLocation = new StaticFeatureSource(features) let i = 0 - this.geolocationState.currentGPSLocation.addCallbackAndRun((location) => { - if (location === undefined) { - return - } - + this.geolocationState.currentGPSLocation.addCallbackAndRunD((location) => { const properties = { id: "gps-" + i, "user:location": "yes", @@ -200,7 +196,6 @@ export default class GeoLocationHandler { ) }) features.ping() - let i = 0 this.currentUserLocation?.features?.addCallbackAndRunD(([location]: [Feature]) => { if (location === undefined) { return @@ -231,7 +226,6 @@ export default class GeoLocationHandler { const feature = JSON.parse(JSON.stringify(location)) feature.properties.id = "gps/" + features.data.length - i++ features.data.push(feature) features.ping() }) diff --git a/src/Logic/Osm/OsmConnection.ts b/src/Logic/Osm/OsmConnection.ts index 1c92f07e0..a6295bd8d 100644 --- a/src/Logic/Osm/OsmConnection.ts +++ b/src/Logic/Osm/OsmConnection.ts @@ -399,11 +399,12 @@ export class OsmConnection { return id } + public static GpxTrackVisibility = ["private", "public", "trackable", "identifiable"] as const public async uploadGpxTrack( gpx: string, options: { description: string - visibility: "private" | "public" | "trackable" | "identifiable" + visibility: (typeof OsmConnection.GpxTrackVisibility)[number] filename?: string /** * Some words to give some properties; @@ -425,11 +426,14 @@ export class OsmConnection { const contents = { file: gpx, - description: options.description ?? "", + description: options.description, tags: options.labels?.join(",") ?? "", visibility: options.visibility, } + if (!contents.description) { + throw "The description of a GPS-trace cannot be the empty string, undefined or null" + } const extras = { file: '; filename="' + diff --git a/src/UI/Base/SubtleButton.ts b/src/UI/Base/SubtleButton.ts index 5eb920b0a..02db03ab2 100644 --- a/src/UI/Base/SubtleButton.ts +++ b/src/UI/Base/SubtleButton.ts @@ -66,32 +66,4 @@ export class SubtleButton extends UIElement { this.SetClass(classes) return button } - - public OnClickWithLoading( - loadingText: BaseUIElement | string, - action: () => Promise - ): BaseUIElement { - const state = new UIEventSource<"idle" | "running">("idle") - const button = this - - button.onClick(async () => { - state.setData("running") - try { - await action() - } catch (e) { - console.error(e) - } finally { - state.setData("idle") - } - }) - const loading = new Lazy(() => new Loading(loadingText)) - return new VariableUiElement( - state.map((st) => { - if (st === "idle") { - return button - } - return loading - }) - ) - } } diff --git a/src/UI/BigComponents/UploadTraceToOsmUI.svelte b/src/UI/BigComponents/UploadTraceToOsmUI.svelte new file mode 100644 index 000000000..f754c5475 --- /dev/null +++ b/src/UI/BigComponents/UploadTraceToOsmUI.svelte @@ -0,0 +1,181 @@ + + + + + {#if !$gpxServerIsOnline} +
+ + +
+ {:else if $currentStep === "error"} +
+ + +
+ {:else if $currentStep === "init"} + + {:else if $currentStep === "please_confirm"} +
uploadTrace()} + class="flex flex-col border-interactive interactive px-2 gap-y-1"> +

+ +

+ + + + +

+ +

+ + + + +