Reset the add point dialog when the popup is closed

This commit is contained in:
pietervdvn 2021-04-08 22:32:15 +02:00
parent 39711373cd
commit 8e15f8488a
3 changed files with 29 additions and 8 deletions

View file

@ -428,11 +428,12 @@ export class InitUiElements {
} }
const newPointDialogIsShown = new UIEventSource<boolean>(false);
const addNewPoint = new ScrollableFullScreen( const addNewPoint = new ScrollableFullScreen(
() => Translations.t.general.add.title.Clone(), () => Translations.t.general.add.title.Clone(),
() => new SimpleAddUI(), () => new SimpleAddUI(newPointDialogIsShown),
"new"); "new",
newPointDialogIsShown)
addNewPoint.isShown.addCallback(isShown => { addNewPoint.isShown.addCallback(isShown => {
if (!isShown) { if (!isShown) {
State.state.LastClickLocation.setData(undefined) State.state.LastClickLocation.setData(undefined)

View file

@ -2,7 +2,7 @@ import { Utils } from "../Utils";
export default class Constants { 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 // The user journey states thresholds when a new feature gets unlocked
public static userJourney = { public static userJourney = {

View file

@ -37,7 +37,7 @@ export default class SimpleAddUI extends UIElement {
private readonly goToInboxButton: UIElement = new SubtleButton(Svg.envelope_ui(), private readonly goToInboxButton: UIElement = new SubtleButton(Svg.envelope_ui(),
Translations.t.general.goToInbox, {url: "https://www.openstreetmap.org/messages/inbox", newTab: false}); Translations.t.general.goToInbox, {url: "https://www.openstreetmap.org/messages/inbox", newTab: false});
constructor() { constructor(isShown: UIEventSource<boolean>) {
super(State.state.locationControl.map(loc => loc.zoom)); super(State.state.locationControl.map(loc => loc.zoom));
const self = this; const self = this;
this.ListenTo(Locale.language); this.ListenTo(Locale.language);
@ -64,6 +64,18 @@ export default class SimpleAddUI extends UIElement {
State.state.layerControlIsOpened.setData(true); 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 { InnerRender(): string {
@ -143,7 +155,9 @@ export default class SimpleAddUI extends UIElement {
"<b>", "<b>",
Translations.t.general.add.confirmButton.Subs({category: preset.name}), Translations.t.general.add.confirmButton.Subs({category: preset.name}),
"</b>"])).SetClass("break-words"); "</b>"])).SetClass("break-words");
confirmButton.onClick(this.CreatePoint(preset.tags)); confirmButton.onClick(
this.CreatePoint(preset.tags)
);
if (!this._confirmPreset.data.layerToAddTo.isDisplayed.data) { if (!this._confirmPreset.data.layerToAddTo.isDisplayed.data) {
return new Combine([ return new Combine([
@ -158,7 +172,7 @@ export default class SimpleAddUI extends UIElement {
let tagInfo = ""; let tagInfo = "";
const csCount = State.state.osmConnection.userDetails.data.csCount; const csCount = State.state.osmConnection.userDetails.data.csCount;
if (csCount > Constants.userJourney.tagsVisibleAt) { 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 = `<br/>More information about the preset: ${tagInfo}` tagInfo = `<br/>More information about the preset: ${tagInfo}`
} }
@ -186,7 +200,7 @@ export default class SimpleAddUI extends UIElement {
const csCount = State.state.osmConnection.userDetails.data.csCount; const csCount = State.state.osmConnection.userDetails.data.csCount;
let tagInfo = undefined; let tagInfo = undefined;
if (csCount > Constants.userJourney.tagsVisibleAt) { 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) tagInfo = new Combine(presets)
} }
const button: UIElement = const button: UIElement =
@ -220,11 +234,17 @@ export default class SimpleAddUI extends UIElement {
private CreatePoint(tags: Tag[]) { private CreatePoint(tags: Tag[]) {
return () => { return () => {
console.log("Create Point Triggered")
const loc = State.state.LastClickLocation.data; const loc = State.state.LastClickLocation.data;
let feature = State.state.changes.createElement(tags, loc.lat, loc.lon); let feature = State.state.changes.createElement(tags, loc.lat, loc.lon);
State.state.selectedElement.setData(feature); State.state.selectedElement.setData(feature);
this._confirmPreset.setData(undefined);
} }
} }
public OnClose(){
console.log("On close triggered")
this._confirmPreset.setData(undefined)
}
} }