From d7e5aa67359e88221e1799582e1939f21f38b978 Mon Sep 17 00:00:00 2001 From: Quincy Morgan Date: Tue, 14 Apr 2020 14:03:18 -0700 Subject: [PATCH] Keep track of the initial hash parameters through multiple loads of the UI (close #7504) --- modules/behavior/hash.js | 6 ------ modules/core/context.js | 13 +++++++------ modules/ui/commit.js | 13 ++++++------- 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/modules/behavior/hash.js b/modules/behavior/hash.js index 888e671e5..fad6d43cf 100644 --- a/modules/behavior/hash.js +++ b/modules/behavior/hash.js @@ -185,12 +185,6 @@ export function behaviorHash(context) { //} } - // Store these here instead of updating local storage since local - // storage could be flushed if the user discards pending changes - if (q.comment) behavior.comment = q.comment; - if (q.source) behavior.source = q.source; - if (q.hashtags) behavior.hashtags = q.hashtags; - if (q.walkthrough === 'true') { behavior.startWalkthrough = true; } diff --git a/modules/core/context.js b/modules/core/context.js index 9edd228a0..0e2055b98 100644 --- a/modules/core/context.js +++ b/modules/core/context.js @@ -29,6 +29,9 @@ export function coreContext() { context.version = '2.17.2'; context.privacyVersion = '20200407'; + // iD will alter the hash so cache the parameters intended to setup the session + context.initialHashParams = window.location.hash ? utilStringQs(window.location.hash) : {}; + context.isFirstSession = !prefs('sawSplash') && !prefs('sawPrivacyVersion'); @@ -455,10 +458,8 @@ export function coreContext() { // might matter if dependents make calls to each other. Be wary of async calls. function initializeDependents() { - const hash = utilStringQs(window.location.hash); - - if (hash.presets) { - presetManager.addablePresetIDs(new Set(hash.presets.split(','))); + if (context.initialHashParams.presets) { + presetManager.addablePresetIDs(new Set(context.initialHashParams.presets.split(','))); } // kick off some async work @@ -477,8 +478,8 @@ export function coreContext() { _features.init(); _photos.init(); - if (services.maprules && hash.maprules) { - d3_json(hash.maprules) + if (services.maprules && context.initialHashParams.maprules) { + d3_json(context.initialHashParams.maprules) .then(mapcss => { services.maprules.init(); mapcss.forEach(mapcssSelector => services.maprules.addRule(mapcssSelector)); diff --git a/modules/ui/commit.js b/modules/ui/commit.js index de7553389..abf991547 100644 --- a/modules/ui/commit.js +++ b/modules/ui/commit.js @@ -75,17 +75,16 @@ export function uiCommit(context) { if (!_changeset) { // load in the URL hash values, if any - var hashBehavior = context.ui().hash; - if (hashBehavior.comment) { - prefs('comment', hashBehavior.comment); + if (context.initialHashParams.comment) { + prefs('comment', context.initialHashParams.comment); prefs('commentDate', Date.now()); } - if (hashBehavior.source) { - prefs('source', hashBehavior.source); + if (context.initialHashParams.source) { + prefs('source', context.initialHashParams.source); prefs('commentDate', Date.now()); } - if (hashBehavior.hashtags) { - prefs('hashtags', hashBehavior.hashtags); + if (context.initialHashParams.hashtags) { + prefs('hashtags', context.initialHashParams.hashtags); } var detected = utilDetect();