From 8e15f8488a1c4d473a1e046530e94ed24a98a771 Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Thu, 8 Apr 2021 22:32:15 +0200 Subject: [PATCH] Reset the add point dialog when the popup is closed --- InitUiElements.ts | 7 ++++--- Models/Constants.ts | 2 +- UI/BigComponents/SimpleAddUI.ts | 28 ++++++++++++++++++++++++---- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/InitUiElements.ts b/InitUiElements.ts index f5e948f..1b5c41a 100644 --- a/InitUiElements.ts +++ b/InitUiElements.ts @@ -428,11 +428,12 @@ export class InitUiElements { } + const newPointDialogIsShown = new UIEventSource(false); const addNewPoint = new ScrollableFullScreen( () => Translations.t.general.add.title.Clone(), - () => new SimpleAddUI(), - "new"); - + () => new SimpleAddUI(newPointDialogIsShown), + "new", + newPointDialogIsShown) addNewPoint.isShown.addCallback(isShown => { if (!isShown) { State.state.LastClickLocation.setData(undefined) diff --git a/Models/Constants.ts b/Models/Constants.ts index 0f73c47..c51b8ac 100644 --- a/Models/Constants.ts +++ b/Models/Constants.ts @@ -2,7 +2,7 @@ import { Utils } from "../Utils"; export default class Constants { - public static vNumber = "0.6.6b"; + public static vNumber = "0.6.6c"; // The user journey states thresholds when a new feature gets unlocked public static userJourney = { diff --git a/UI/BigComponents/SimpleAddUI.ts b/UI/BigComponents/SimpleAddUI.ts index 0574d9d..9f1a109 100644 --- a/UI/BigComponents/SimpleAddUI.ts +++ b/UI/BigComponents/SimpleAddUI.ts @@ -37,7 +37,7 @@ export default class SimpleAddUI extends UIElement { private readonly goToInboxButton: UIElement = new SubtleButton(Svg.envelope_ui(), Translations.t.general.goToInbox, {url: "https://www.openstreetmap.org/messages/inbox", newTab: false}); - constructor() { + constructor(isShown: UIEventSource) { super(State.state.locationControl.map(loc => loc.zoom)); const self = this; this.ListenTo(Locale.language); @@ -64,6 +64,18 @@ export default class SimpleAddUI extends UIElement { State.state.layerControlIsOpened.setData(true); }) + // IS shown is the state of the dialog - we reset the choice if the dialog dissappears + isShown.addCallback(isShown => + { + if(!isShown){ + self._confirmPreset.setData(undefined) + } + }) + // If the click location changes, we reset the dialog as well + State.state.LastClickLocation.addCallback(() => { + self._confirmPreset.setData(undefined) + }) + } InnerRender(): string { @@ -143,7 +155,9 @@ export default class SimpleAddUI extends UIElement { "", Translations.t.general.add.confirmButton.Subs({category: preset.name}), ""])).SetClass("break-words"); - confirmButton.onClick(this.CreatePoint(preset.tags)); + confirmButton.onClick( + this.CreatePoint(preset.tags) + ); if (!this._confirmPreset.data.layerToAddTo.isDisplayed.data) { return new Combine([ @@ -158,7 +172,7 @@ export default class SimpleAddUI extends UIElement { let tagInfo = ""; const csCount = State.state.osmConnection.userDetails.data.csCount; if (csCount > Constants.userJourney.tagsVisibleAt) { - tagInfo = this._confirmPreset.data.tags.map(t => t.asHumanString(csCount > Constants.userJourney.tagsVisibleAndWikiLinked, true, {})).join("&"); + tagInfo = this._confirmPreset.data.tags.map(t => t.asHumanString(csCount > Constants.userJourney.tagsVisibleAndWikiLinked, true)).join("&"); tagInfo = `
More information about the preset: ${tagInfo}` } @@ -186,7 +200,7 @@ export default class SimpleAddUI extends UIElement { const csCount = State.state.osmConnection.userDetails.data.csCount; let tagInfo = undefined; if (csCount > Constants.userJourney.tagsVisibleAt) { - const presets = preset.tags.map(t => new Combine ([t.asHumanString(false, true, {}), " "]).SetClass("subtle break-words") ) + const presets = preset.tags.map(t => new Combine([t.asHumanString(false, true), " "]).SetClass("subtle break-words")) tagInfo = new Combine(presets) } const button: UIElement = @@ -220,11 +234,17 @@ export default class SimpleAddUI extends UIElement { private CreatePoint(tags: Tag[]) { return () => { + console.log("Create Point Triggered") const loc = State.state.LastClickLocation.data; let feature = State.state.changes.createElement(tags, loc.lat, loc.lon); State.state.selectedElement.setData(feature); + this._confirmPreset.setData(undefined); } } + public OnClose(){ + console.log("On close triggered") + this._confirmPreset.setData(undefined) + } } \ No newline at end of file