From ddc0aebdc3236c2b6f65c8d6c424293f14aa466c Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Mon, 18 Jul 2022 00:28:26 +0200 Subject: [PATCH] Fix addition of new points --- UI/BigComponents/SimpleAddUI.ts | 19 ++++++++++--- UI/DashboardGui.ts | 47 ++++++++++++++++++++++++++------- 2 files changed, 52 insertions(+), 14 deletions(-) diff --git a/UI/BigComponents/SimpleAddUI.ts b/UI/BigComponents/SimpleAddUI.ts index 78fa604a0d..4566f4115b 100644 --- a/UI/BigComponents/SimpleAddUI.ts +++ b/UI/BigComponents/SimpleAddUI.ts @@ -43,6 +43,14 @@ export interface PresetInfo extends PresetConfig { export default class SimpleAddUI extends Toggle { + /** + * + * @param isShown + * @param resetScrollSignal + * @param filterViewIsOpened + * @param state + * @param takeLocationFrom: defaults to state.lastClickLocation. Take this location to add the new point around + */ constructor(isShown: UIEventSource, resetScrollSignal: UIEventSource, filterViewIsOpened: UIEventSource, @@ -59,7 +67,9 @@ export default class SimpleAddUI extends Toggle { filteredLayers: UIEventSource, featureSwitchFilter: UIEventSource, backgroundLayer: UIEventSource - }) { + }, + takeLocationFrom?: UIEventSource<{lat: number, lon: number}> + ) { const loginButton = new SubtleButton(Svg.osm_logo_ui(), Translations.t.general.add.pleaseLogin.Clone()) .onClick(() => state.osmConnection.AttemptLogin()); const readYourMessages = new Combine([ @@ -68,7 +78,8 @@ export default class SimpleAddUI extends Toggle { Translations.t.general.goToInbox, {url: "https://www.openstreetmap.org/messages/inbox", newTab: false}) ]); - + + takeLocationFrom = takeLocationFrom ?? state.LastClickLocation const selectedPreset = new UIEventSource(undefined); selectedPreset.addCallback(_ => { resetScrollSignal.ping(); @@ -76,7 +87,7 @@ export default class SimpleAddUI extends Toggle { isShown.addCallback(_ => selectedPreset.setData(undefined)) // Clear preset selection when the UI is closed/opened - state.LastClickLocation.addCallback(_ => selectedPreset.setData(undefined)) + takeLocationFrom.addCallback(_ => selectedPreset.setData(undefined)) const presetsOverview = SimpleAddUI.CreateAllPresetsPanel(selectedPreset, state) @@ -120,7 +131,7 @@ export default class SimpleAddUI extends Toggle { const message = Translations.t.general.add.addNew.Subs({category: preset.name}, preset.name["context"]); return new ConfirmLocationOfPoint(state, filterViewIsOpened, preset, message, - state.LastClickLocation.data, + takeLocationFrom.data, confirm, cancel, () => { diff --git a/UI/DashboardGui.ts b/UI/DashboardGui.ts index 68e207e302..acf0ea5a16 100644 --- a/UI/DashboardGui.ts +++ b/UI/DashboardGui.ts @@ -25,8 +25,7 @@ import FilterView from "./BigComponents/FilterView"; import {FilterState} from "../Models/FilteredLayer"; import Translations from "./i18n/Translations"; import Constants from "../Models/Constants"; -import {Layer} from "leaflet"; -import doc = Mocha.reporters.doc; +import SimpleAddUI from "./BigComponents/SimpleAddUI"; export default class DashboardGui { @@ -152,11 +151,11 @@ export default class DashboardGui { private allDocumentationButtons(): BaseUIElement { const layers = this.state.layoutToUse.layers.filter(l => Constants.priviliged_layers.indexOf(l.id) < 0) .filter(l => !l.id.startsWith("note_import_")); - - if(layers.length === 1){ + + if (layers.length === 1) { return this.documentationButtonFor(layers[0]) } - return this.viewSelector(new FixedUiElement("Documentation"), "Documentation", + return this.viewSelector(new FixedUiElement("Documentation"), "Documentation", new Combine(layers.map(l => this.documentationButtonFor(l).SetClass("flex flex-col")))) } @@ -196,10 +195,39 @@ export default class DashboardGui { } }) + const filterView = new Lazy(() => { + return new FilterView(state.filteredLayers, state.overlayToggles) + }); const welcome = new Combine([state.layoutToUse.description, state.layoutToUse.descriptionTail]) self.currentView.setData({title: state.layoutToUse.title, contents: welcome}) + const filterViewIsOpened = new UIEventSource(false) + filterViewIsOpened.addCallback(fv => self.currentView.setData({title: "filters", contents: filterView})) + + const newPointIsShown = new UIEventSource(false); + const addNewPoint = new SimpleAddUI( + new UIEventSource(true), + new UIEventSource(undefined), + filterViewIsOpened, + state, + state.locationControl + ); + const addNewPointTitle = "Add a missing point" + this.currentView.addCallbackAndRunD(cv => { + newPointIsShown.setData(cv.contents === addNewPoint) + }) + newPointIsShown.addCallbackAndRun(isShown => { + if(isShown){ + if(self.currentView.data.contents !== addNewPoint){ + self.currentView.setData({title: addNewPointTitle, contents: addNewPoint}) + } + }else{ + if(self.currentView.data.contents === addNewPoint){ + self.currentView.setData(undefined) + } + } + }) + new Combine([ - new Combine([ this.viewSelector(new Title(state.layoutToUse.title.Clone(), 2), state.layoutToUse.title.Clone(), welcome, "welcome"), map.SetClass("w-full h-64 shrink-0 rounded-lg"), @@ -210,10 +238,9 @@ export default class DashboardGui { new FixedUiElement("Stats"), "statistics"), this.viewSelector(new FixedUiElement("Filter"), - "Filters", - new Lazy(() => { - return new FilterView(state.filteredLayers, state.overlayToggles) - }), "filters" + "Filters", filterView, "filters"), + this.viewSelector(new Combine([ "Add a missing point"]), addNewPointTitle, + addNewPoint ), new VariableUiElement(elementsInview.map(elements => this.mainElementsView(elements).SetClass("block m-2")))