From 39e6cdfda4bef5a4b726590ac1a5299e52648dd4 Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Wed, 16 Feb 2022 01:46:55 +0100 Subject: [PATCH] Fix dependency injection of refactoring --- Logic/Osm/Changes.ts | 11 ++++++++--- Logic/State/ElementsState.ts | 14 ++------------ Logic/State/MapState.ts | 1 + Logic/State/UserRelatedState.ts | 14 ++++++++++++++ 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/Logic/Osm/Changes.ts b/Logic/Osm/Changes.ts index 0aa0cd7efb..10640991fc 100644 --- a/Logic/Osm/Changes.ts +++ b/Logic/Osm/Changes.ts @@ -27,8 +27,10 @@ export class Changes { public features = new UIEventSource<{ feature: any, freshness: Date }[]>([]); public readonly pendingChanges: UIEventSource = LocalStorageSource.GetParsed("pending-changes", []) public readonly allChanges = new UIEventSource(undefined) - public readonly state: { allElements: ElementStorage; historicalUserLocations: FeatureSource; osmConnection: OsmConnection } + public readonly state: { allElements: ElementStorage; osmConnection: OsmConnection } public readonly extraComment: UIEventSource = new UIEventSource(undefined) + + private historicalUserLocations: FeatureSource private _nextId: number = -1; // Newly assigned ID's are negative private readonly isUploading = new UIEventSource(false); private readonly previouslyCreated: OsmObject[] = [] @@ -38,7 +40,6 @@ export class Changes { constructor( state?: { allElements: ElementStorage, - historicalUserLocations: FeatureSource, osmConnection: OsmConnection }, leftRightSensitive: boolean = false) { @@ -148,7 +149,7 @@ export class Changes { private calculateDistanceToChanges(change: OsmChangeAction, changeDescriptions: ChangeDescription[]) { - const locations = this.state?.historicalUserLocations?.features?.data + const locations = this.historicalUserLocations?.features?.data if (locations === undefined) { // No state loaded or no locations -> we can't calculate... return; @@ -520,4 +521,8 @@ export class Changes { console.debug("Calculated the pending changes: ", result.newObjects.length, "new; ", result.modifiedObjects.length, "modified;", result.deletedObjects, "deleted") return result } + + public setHistoricalUserLocations(locations: FeatureSource ){ + this.historicalUserLocations = locations + } } \ No newline at end of file diff --git a/Logic/State/ElementsState.ts b/Logic/State/ElementsState.ts index 496d1fd511..c7fc1dbbf4 100644 --- a/Logic/State/ElementsState.ts +++ b/Logic/State/ElementsState.ts @@ -20,11 +20,7 @@ export default class ElementsState extends FeatureSwitchState { The mapping from id -> UIEventSource */ public allElements: ElementStorage = new ElementStorage(); - /** - THe change handler - */ - public changes: Changes; - + /** The latest element that was selected */ @@ -48,9 +44,6 @@ export default class ElementsState extends FeatureSwitchState { constructor(layoutToUse: LayoutConfig) { super(layoutToUse); - // @ts-ignore - this.changes = new Changes(this, layoutToUse?.isLeftRightSensitive() ?? false) - { // -- Location control initialization const zoom = UIEventSource.asFloat( QueryParameters.GetQueryParameter( @@ -85,10 +78,7 @@ export default class ElementsState extends FeatureSwitchState { lat.setData(latlonz.lat); lon.setData(latlonz.lon); }); - } - - new ChangeToElementsActor(this.changes, this.allElements) - new PendingChangesUploader(this.changes, this.selectedElement); + } } \ No newline at end of file diff --git a/Logic/State/MapState.ts b/Logic/State/MapState.ts index 938df9fac3..387885a9ce 100644 --- a/Logic/State/MapState.ts +++ b/Logic/State/MapState.ts @@ -271,6 +271,7 @@ export default class MapState extends UserRelatedState { let gpsLayerDef: FilteredLayer = this.filteredLayers.data.filter(l => l.layerDef.id === "gps_location_history")[0] if (gpsLayerDef !== undefined) { this.historicalUserLocations = new SimpleFeatureSource(gpsLayerDef, Tiles.tile_index(0, 0, 0), features); + this.changes.setHistoricalUserLocations(this.historicalUserLocations) } diff --git a/Logic/State/UserRelatedState.ts b/Logic/State/UserRelatedState.ts index 5450e51b82..6d6f8ae892 100644 --- a/Logic/State/UserRelatedState.ts +++ b/Logic/State/UserRelatedState.ts @@ -8,6 +8,9 @@ import {Utils} from "../../Utils"; import Locale from "../../UI/i18n/Locale"; import ElementsState from "./ElementsState"; import SelectedElementTagsUpdater from "../Actors/SelectedElementTagsUpdater"; +import {Changes} from "../Osm/Changes"; +import ChangeToElementsActor from "../Actors/ChangeToElementsActor"; +import PendingChangesUploader from "../Actors/PendingChangesUploader"; /** * The part of the state which keeps track of user-related stuff, e.g. the OSM-connection, @@ -20,6 +23,10 @@ export default class UserRelatedState extends ElementsState { The user credentials */ public osmConnection: OsmConnection; + /** + THe change handler + */ + public changes: Changes; /** * The key for mangrove */ @@ -44,6 +51,13 @@ export default class UserRelatedState extends ElementsState { attemptLogin: options?.attemptLogin }) + + this.changes = new Changes(this, layoutToUse?.isLeftRightSensitive() ?? false) + + + new ChangeToElementsActor(this.changes, this.allElements) + new PendingChangesUploader(this.changes, this.selectedElement); + this.mangroveIdentity = new MangroveIdentity( this.osmConnection.GetLongPreference("identity", "mangrove") );