From 17503d5bfb63c5c03968c96f15c2c5a674a3ede3 Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Wed, 11 Oct 2023 01:41:42 +0200 Subject: [PATCH] Fix: hide some elements of the UI if they are disabled by a featureSwitch --- .../Sources/LastClickFeatureSource.ts | 50 ++-- src/Logic/State/FeatureSwitchState.ts | 2 +- src/Models/ThemeViewState.ts | 92 +++--- src/UI/Base/TabbedGroup.svelte | 180 ++++++------ src/UI/BigComponents/ThemeIntroPanel.svelte | 183 ++++++------ src/UI/ThemeViewGUI.svelte | 261 +++++++++--------- 6 files changed, 402 insertions(+), 366 deletions(-) diff --git a/src/Logic/FeatureSource/Sources/LastClickFeatureSource.ts b/src/Logic/FeatureSource/Sources/LastClickFeatureSource.ts index b45169c0a..40705891f 100644 --- a/src/Logic/FeatureSource/Sources/LastClickFeatureSource.ts +++ b/src/Logic/FeatureSource/Sources/LastClickFeatureSource.ts @@ -12,57 +12,57 @@ import { OsmTags } from "../../../Models/OsmFeature"; * Based on a lon/lat UIEVentSource, will generate the corresponding feature with the correct properties */ export class LastClickFeatureSource implements WritableFeatureSource { - public readonly features: UIEventSource = new UIEventSource([]) - private i: number = 0 - private readonly hasNoteLayer: string - private readonly renderings: string[]; - private readonly hasPresets: string; + public readonly features: UIEventSource = new UIEventSource([]); + public readonly hasNoteLayer: boolean; + public readonly renderings: string[]; + public readonly hasPresets: boolean; + private i: number = 0; constructor(location: Store<{ lon: number; lat: number }>, layout: LayoutConfig) { - this.hasNoteLayer = layout.layers.some((l) => l.id === "note") ? "yes" : "no" - this.hasPresets= layout.layers.some((l) => l.presets?.length > 0) ? "yes" : "no" - const allPresets: BaseUIElement[] = [] + this.hasNoteLayer = layout.layers.some((l) => l.id === "note"); + this.hasPresets = layout.layers.some((l) => l.presets?.length > 0); + const allPresets: BaseUIElement[] = []; for (const layer of layout.layers) for (let i = 0; i < (layer.presets ?? []).length; i++) { - const preset = layer.presets[i] - const tags = new ImmutableStore(TagUtils.KVtoProperties(preset.tags)) + const preset = layer.presets[i]; + const tags = new ImmutableStore(TagUtils.KVtoProperties(preset.tags)); const { html } = layer.mapRendering[0].RenderIcon(tags, false, { noSize: true, - includeBadges: false, - }) - allPresets.push(html) + includeBadges: false + }); + allPresets.push(html); } this.renderings = Utils.Dedup( allPresets.map((uiElem) => Utils.runningFromConsole ? "" : uiElem.ConstructElement().innerHTML ) - ) + ); location.addCallbackAndRunD(({ lon, lat }) => { - this.features.setData([this.createFeature(lon, lat)]) - }) + this.features.setData([this.createFeature(lon, lat)]); + }); } public createFeature(lon: number, lat: number): Feature { const properties: OsmTags = { lastclick: "yes", id: "last_click_" + this.i, - has_note_layer: this.hasNoteLayer , - has_presets:this.hasPresets , + has_note_layer: this.hasNoteLayer ? "yes" : "no", + has_presets: this.hasPresets ? "yes" : "no", renderings: this.renderings.join(""), - number_of_presets: "" +this. renderings.length, - first_preset: this.renderings[0], - } - this. i++ + number_of_presets: "" + this.renderings.length, + first_preset: this.renderings[0] + }; + this.i++; return >{ type: "Feature", properties, geometry: { type: "Point", - coordinates: [lon, lat], - }, - } + coordinates: [lon, lat] + } + }; } } diff --git a/src/Logic/State/FeatureSwitchState.ts b/src/Logic/State/FeatureSwitchState.ts index 3fda13afd..a12835fbb 100644 --- a/src/Logic/State/FeatureSwitchState.ts +++ b/src/Logic/State/FeatureSwitchState.ts @@ -99,7 +99,7 @@ export default class FeatureSwitchState extends OsmConnectionFeatureSwitches { ) this.featureSwitchCommunityIndex = FeatureSwitchUtils.initSwitch( "fs-community-index", - true, + this.featureSwitchEnableLogin.data, "Disables/enables the button to get in touch with the community" ) this.featureSwitchExtraLinkEnabled = FeatureSwitchUtils.initSwitch( diff --git a/src/Models/ThemeViewState.ts b/src/Models/ThemeViewState.ts index 6a03a41d9..f52da26f5 100644 --- a/src/Models/ThemeViewState.ts +++ b/src/Models/ThemeViewState.ts @@ -338,7 +338,6 @@ export default class ThemeViewState implements SpecialVisualizationState { ); this.initActors(); - // TODO remove this.addLastClick(lastClick); this.drawSpecialLayers(); this.initHotkeys(); this.miscSetup(); @@ -417,52 +416,61 @@ export default class ThemeViewState implements SpecialVisualizationState { } ); - Hotkeys.RegisterHotkey( - { - nomod: "b" - }, - Translations.t.hotkeyDocumentation.openLayersPanel, - () => { - if (this.featureSwitches.featureSwitchFilter.data) { - this.guistate.openFilterView(); + this.featureSwitches.featureSwitchBackgroundSelection.addCallbackAndRun(enable => { + if(!enable){ + return } - } - ); + Hotkeys.RegisterHotkey( + { + nomod: "b" + }, + Translations.t.hotkeyDocumentation.openLayersPanel, + () => { + if (this.featureSwitches.featureSwitchFilter.data) { + this.guistate.openFilterView(); + } + } + ); + Hotkeys.RegisterHotkey( + { shift: "O" }, + Translations.t.hotkeyDocumentation.selectMapnik, + () => { + this.mapProperties.rasterLayer.setData(AvailableRasterLayers.osmCarto); + } + ); + const setLayerCategory = (category: EliCategory) => { + const available = this.availableLayers.data; + const current = this.mapProperties.rasterLayer; + const best = RasterLayerUtils.SelectBestLayerAccordingTo( + available, + category, + current.data + ); + console.log("Best layer for category", category, "is", best.properties.id); + current.setData(best); + }; + + Hotkeys.RegisterHotkey( + { nomod: "O" }, + Translations.t.hotkeyDocumentation.selectOsmbasedmap, + () => setLayerCategory("osmbasedmap") + ); + + Hotkeys.RegisterHotkey({ nomod: "M" }, Translations.t.hotkeyDocumentation.selectMap, () => + setLayerCategory("map") + ); + + Hotkeys.RegisterHotkey( + { nomod: "P" }, + Translations.t.hotkeyDocumentation.selectAerial, + () => setLayerCategory("photo") + ); + return true + }) - Hotkeys.RegisterHotkey( - { shift: "O" }, - Translations.t.hotkeyDocumentation.selectMapnik, - () => { - this.mapProperties.rasterLayer.setData(AvailableRasterLayers.osmCarto); - } - ); - const setLayerCategory = (category: EliCategory) => { - const available = this.availableLayers.data; - const current = this.mapProperties.rasterLayer; - const best = RasterLayerUtils.SelectBestLayerAccordingTo( - available, - category, - current.data - ); - console.log("Best layer for category", category, "is", best.properties.id); - current.setData(best); - }; - Hotkeys.RegisterHotkey( - { nomod: "O" }, - Translations.t.hotkeyDocumentation.selectOsmbasedmap, - () => setLayerCategory("osmbasedmap") - ); - Hotkeys.RegisterHotkey({ nomod: "M" }, Translations.t.hotkeyDocumentation.selectMap, () => - setLayerCategory("map") - ); - Hotkeys.RegisterHotkey( - { nomod: "P" }, - Translations.t.hotkeyDocumentation.selectAerial, - () => setLayerCategory("photo") - ); } private addLastClick(last_click: LastClickFeatureSource) { diff --git a/src/UI/Base/TabbedGroup.svelte b/src/UI/Base/TabbedGroup.svelte index 7e33100e7..35d9a865b 100644 --- a/src/UI/Base/TabbedGroup.svelte +++ b/src/UI/Base/TabbedGroup.svelte @@ -1,20 +1,32 @@
@@ -29,41 +41,31 @@ >
- {#if $$slots.title1} - twJoin("tab", selected && "primary")}> -
- Tab 0 -
-
- {/if} - {#if $$slots.title1} - twJoin("tab", selected && "primary")}> -
- -
-
- {/if} - {#if $$slots.title2} - twJoin("tab", selected && "primary")}> -
- -
-
- {/if} - {#if $$slots.title3} - twJoin("tab", selected && "primary")}> -
- -
-
- {/if} - {#if $$slots.title4} - twJoin("tab", selected && "primary")}> -
- -
-
- {/if} + twJoin("tab", selected && "primary", !$condition0 && "hidden")}> +
+ Tab 0 +
+
+ twJoin("tab", selected && "primary", !$condition1 && "hidden")}> +
+ +
+
+ twJoin("tab", selected && "primary", !$condition2 && "hidden")}> +
+ +
+
+ twJoin("tab", selected && "primary", !$condition3 && "hidden")}> +
+ +
+
+ twJoin("tab", selected && "primary", !$condition4 && "hidden")}> +
+ +
+
@@ -75,16 +77,24 @@ - + +
+ - + +
+ - + +
+ - + +
+
@@ -92,44 +102,44 @@
diff --git a/src/UI/BigComponents/ThemeIntroPanel.svelte b/src/UI/BigComponents/ThemeIntroPanel.svelte index a109862d5..a65c28906 100644 --- a/src/UI/BigComponents/ThemeIntroPanel.svelte +++ b/src/UI/BigComponents/ThemeIntroPanel.svelte @@ -1,47 +1,48 @@
@@ -62,61 +63,67 @@
-
- {#if $currentGPSLocation !== undefined || $geopermission === "prompt"} - - - {:else if $geopermission === "requested"} - - {:else if $geopermission === "denied"} - - {:else} - - {/if} -
-
- state.guistate.themeIsOpened.setData(false)} - on:searchIsValid={(isValid) => { +
+ + {#if $currentGPSLocation !== undefined || $geopermission === "prompt"} + + + {:else if $geopermission === "requested"} + + {:else if $geopermission === "denied"} + + {:else} + + {/if} + + + + +
+
+ state.guistate.themeIsOpened.setData(false)} + on:searchIsValid={(isValid) => { searchEnabled = isValid }} - perLayer={state.perLayer} - {selectedElement} - {selectedLayer} - {triggerSearch} - /> + perLayer={state.perLayer} + {selectedElement} + {selectedLayer} + {triggerSearch} + /> +
+
- -
+
diff --git a/src/UI/ThemeViewGUI.svelte b/src/UI/ThemeViewGUI.svelte index 5bbbed5a3..878b4ee16 100644 --- a/src/UI/ThemeViewGUI.svelte +++ b/src/UI/ThemeViewGUI.svelte @@ -1,114 +1,114 @@
@@ -169,19 +169,28 @@
- - - - + + {#if state.lastClickObject.hasPresets || state.lastClickObject.hasNoteLayer} + + {/if} + +