diff --git a/Logic/Osm/Actions/DeleteAction.ts b/Logic/Osm/Actions/DeleteAction.ts index 87f412c10..9ab5fab49 100644 --- a/Logic/Osm/Actions/DeleteAction.ts +++ b/Logic/Osm/Actions/DeleteAction.ts @@ -49,18 +49,22 @@ export default class DeleteAction extends OsmChangeAction { /** * * import {OsmNode} from "../OsmObject" + * import { ImmutableStore } from "../../UIEventSource"; + * import { OsmConnection } from "../OsmConnection"; * * const obj : OsmNode= new OsmNode(1) * obj.tags = {id:"node/1",name:"Monte Piselli - San Giacomo"} * const da = new DeleteAction("node/1", new Tag("man_made",""), {theme: "test", specialMotivation: "Testcase"}, true) - * const descr = await da.CreateChangeDescriptions(new Changes(), obj) + * const state = { dryRun: new ImmutableStore(true), osmConnection: new OsmConnection() } + * const descr = await da.CreateChangeDescriptions(new Changes(state), obj) * descr[0] // => {doDelete: true, meta: {theme: "test", specialMotivation: "Testcase",changeType: "deletion"}, type: "node",id: 1 } * * // Must not crash if softDeletionTags are undefined * const da = new DeleteAction("node/1", undefined, {theme: "test", specialMotivation: "Testcase"}, true) * const obj : OsmNode= new OsmNode(1) * obj.tags = {id:"node/1",name:"Monte Piselli - San Giacomo"} - * const descr = await da.CreateChangeDescriptions(new Changes(), obj) + * const state = { dryRun: new ImmutableStore(true), osmConnection: new OsmConnection() } + * const descr = await da.CreateChangeDescriptions(new Changes(state), obj) * descr[0] // => {doDelete: true, meta: {theme: "test", specialMotivation: "Testcase", changeType: "deletion"}, type: "node",id: 1 } */ public async CreateChangeDescriptions( diff --git a/Logic/Osm/Changes.ts b/Logic/Osm/Changes.ts index b19b1b5e8..f4cba09ac 100644 --- a/Logic/Osm/Changes.ts +++ b/Logic/Osm/Changes.ts @@ -1,12 +1,12 @@ import { OsmNode, OsmObject, OsmRelation, OsmWay } from "./OsmObject" -import { UIEventSource } from "../UIEventSource" +import { Store, UIEventSource } from "../UIEventSource" import Constants from "../../Models/Constants" import OsmChangeAction from "./Actions/OsmChangeAction" import { ChangeDescription, ChangeDescriptionTools } from "./Actions/ChangeDescription" import { Utils } from "../../Utils" import { LocalStorageSource } from "../Web/LocalStorageSource" import SimpleMetaTagger from "../SimpleMetaTagger" -import {FeatureSource, IndexedFeatureSource } from "../FeatureSource/FeatureSource" +import { FeatureSource, IndexedFeatureSource } from "../FeatureSource/FeatureSource" import { GeoLocationPointProperties } from "../State/GeoLocationState" import { GeoOperations } from "../GeoOperations" import { ChangesetHandler, ChangesetTag } from "./ChangesetHandler" @@ -25,10 +25,10 @@ export class Changes { public readonly pendingChanges: UIEventSource = LocalStorageSource.GetParsed("pending-changes", []) public readonly allChanges = new UIEventSource(undefined) - public readonly state: { allElements: IndexedFeatureSource; osmConnection: OsmConnection } + public readonly state: { allElements?: IndexedFeatureSource; osmConnection: OsmConnection } public readonly extraComment: UIEventSource = new UIEventSource(undefined) - private readonly historicalUserLocations: FeatureSource + private readonly historicalUserLocations?: FeatureSource private _nextId: number = -1 // Newly assigned ID's are negative private readonly isUploading = new UIEventSource(false) private readonly previouslyCreated: OsmObject[] = [] @@ -36,12 +36,12 @@ export class Changes { private readonly _changesetHandler: ChangesetHandler constructor( - state?: { - dryRun: UIEventSource - allElements: IndexedFeatureSource - featurePropertiesStore: FeaturePropertiesStore + state: { + dryRun: Store + allElements?: IndexedFeatureSource + featurePropertiesStore?: FeaturePropertiesStore osmConnection: OsmConnection - historicalUserLocations: FeatureSource + historicalUserLocations?: FeatureSource }, leftRightSensitive: boolean = false ) { @@ -190,9 +190,11 @@ export class Changes { const changedObjectCoordinates: [number, number][] = [] - const feature = this.state.allElements.featuresById.data.get(change.mainObjectId) - if (feature !== undefined) { - changedObjectCoordinates.push(GeoOperations.centerpointCoordinates(feature)) + { + const feature = this.state.allElements?.featuresById?.data.get(change.mainObjectId) + if (feature !== undefined) { + changedObjectCoordinates.push(GeoOperations.centerpointCoordinates(feature)) + } } for (const changeDescription of changeDescriptions) { diff --git a/Logic/Osm/ChangesetHandler.ts b/Logic/Osm/ChangesetHandler.ts index 812da652c..4641567f4 100644 --- a/Logic/Osm/ChangesetHandler.ts +++ b/Logic/Osm/ChangesetHandler.ts @@ -1,6 +1,6 @@ import escapeHtml from "escape-html" import UserDetails, { OsmConnection } from "./OsmConnection" -import { UIEventSource } from "../UIEventSource" +import { Store, UIEventSource } from "../UIEventSource" import Locale from "../../UI/i18n/Locale" import Constants from "../../Models/Constants" import { Changes } from "./Changes" @@ -16,7 +16,7 @@ export class ChangesetHandler { private readonly allElements: { addAlias: (id0: String, id1: string) => void } private osmConnection: OsmConnection private readonly changes: Changes - private readonly _dryRun: UIEventSource + private readonly _dryRun: Store private readonly userDetails: UIEventSource private readonly backend: string @@ -27,9 +27,9 @@ export class ChangesetHandler { private readonly _remappings = new Map() constructor( - dryRun: UIEventSource, + dryRun: Store, osmConnection: OsmConnection, - allElements: { addAlias: (id0: string, id1: string) => void }, + allElements: { addAlias: (id0: string, id1: string) => void } | undefined, changes: Changes ) { this.osmConnection = osmConnection @@ -299,7 +299,7 @@ export class ChangesetHandler { } for (const mapping of mappings) { const [oldId, newId] = mapping - this.allElements.addAlias(oldId, newId) + this.allElements?.addAlias(oldId, newId) if (newId !== undefined) { this._remappings.set(mapping[0], mapping[1]) } diff --git a/UI/SpecialVisualizations.ts b/UI/SpecialVisualizations.ts index 910be1a57..77ac68c26 100644 --- a/UI/SpecialVisualizations.ts +++ b/UI/SpecialVisualizations.ts @@ -83,13 +83,13 @@ export default class SpecialVisualizations { * Note that _normal_ substitutions are ignored. * * // Return empty list on empty input - * SubstitutedTranslation.constructSpecification("") // => [] + * SpecialVisualizations.constructSpecification("") // => [] * * // Advanced cases with commas, braces and newlines should be handled without problem - * const templates = SubstitutedTranslation.constructSpecification("{send_email(&LBRACEemail&RBRACE,Broken bicycle pump,Hello&COMMA\n\nWith this email&COMMA I'd like to inform you that the bicycle pump located at https://mapcomplete.osm.be/cyclofix?lat=&LBRACE_lat&RBRACE&lon=&LBRACE_lon&RBRACE&z=18#&LBRACEid&RBRACE is broken.\n\n Kind regards,Report this bicycle pump as broken)}") - * const templ = templates[0] - * templ.special.func.funcName // => "send_email" - * templ.special.args[0] = "{email}" + * const templates = SpecialVisualizations.constructSpecification("{send_email(&LBRACEemail&RBRACE,Broken bicycle pump,Hello&COMMA\n\nWith this email&COMMA I'd like to inform you that the bicycle pump located at https://mapcomplete.osm.be/cyclofix?lat=&LBRACE_lat&RBRACE&lon=&LBRACE_lon&RBRACE&z=18#&LBRACEid&RBRACE is broken.\n\n Kind regards,Report this bicycle pump as broken)}") + * const templ = > templates[0] + * templ.func.funcName // => "send_email" + * templ.args[0] = "{email}" */ public static constructSpecification( template: string,