diff --git a/modules/behavior/hash.js b/modules/behavior/hash.js index 56667f8cd..853b8f42c 100644 --- a/modules/behavior/hash.js +++ b/modules/behavior/hash.js @@ -97,19 +97,11 @@ export function behaviorHash(context) { context.zoomToEntity(q.id.split(',')[0], !q.map); } - if (q.comment) { - context.storage('comment', q.comment); - context.storage('commentDate', Date.now()); - } - - if (q.source) { - context.storage('source', q.source); - context.storage('commentDate', Date.now()); - } - - if (q.hashtags) { - context.storage('hashtags', q.hashtags); - } + // 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/history.js b/modules/core/history.js index acb0d97d5..f7b50fcf9 100644 --- a/modules/core/history.js +++ b/modules/core/history.js @@ -643,7 +643,14 @@ export function coreHistory(context) { clearSaved: function() { context.debouncedSave.cancel(); - if (lock.locked()) context.storage(getKey('saved_history'), null); + if (lock.locked()) { + context.storage(getKey('saved_history'), null); + + // clear the changeset metadata associated with the saved history + context.storage('comment', null); + context.storage('hashtags', null); + context.storage('source', null); + } return history; }, diff --git a/modules/ui/commit.js b/modules/ui/commit.js index f0ad66004..a653484ba 100644 --- a/modules/ui/commit.js +++ b/modules/ui/commit.js @@ -65,6 +65,21 @@ export function uiCommit(context) { // Initialize changeset if one does not exist yet. // Also pull values from local storage. if (!_changeset) { + + // load in the URL hash values, if any + var hash = context.ui().hash; + if (hash.comment) { + context.storage('comment', hash.comment); + context.storage('commentDate', Date.now()); + } + if (hash.source) { + context.storage('source', hash.source); + context.storage('commentDate', Date.now()); + } + if (hash.hashtags) { + context.storage('hashtags', hash.hashtags); + } + var detected = utilDetect(); tags = { comment: context.storage('comment') || '', @@ -94,7 +109,7 @@ export function uiCommit(context) { if (sources.indexOf('streetlevel imagery') === -1) { sources.push('streetlevel imagery'); } - + // add the photo overlays used during editing as sources photoOverlaysUsed.forEach(function(photoOverlay) { if (sources.indexOf(photoOverlay) === -1) { diff --git a/modules/ui/init.js b/modules/ui/init.js index 1e9752268..695ce94fa 100644 --- a/modules/ui/init.js +++ b/modules/ui/init.js @@ -221,9 +221,9 @@ export function uiInit(context) { ui.onResize(); map.redrawEnable(true); - var hash = behaviorHash(context); - hash(); - if (!hash.hadHash) { + ui.hash = behaviorHash(context); + ui.hash(); + if (!ui.hash.hadHash) { map.centerZoom([0, 0], 2); } @@ -291,7 +291,7 @@ export function uiInit(context) { context.enter(modeBrowse(context)); if (!_initCounter++) { - if (!hash.startWalkthrough) { + if (!ui.hash.startWalkthrough) { context.container() .call(uiSplash(context)) .call(uiRestore(context)); @@ -317,8 +317,8 @@ export function uiInit(context) { _initCounter++; - if (hash.startWalkthrough) { - hash.startWalkthrough = false; + if (ui.hash.startWalkthrough) { + ui.hash.startWalkthrough = false; context.container().call(uiIntro(context)); }