mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-15 13:38:26 +02:00
Improve endpoint for checking if restorable changes exist (re: b4ef0862978ae79a5cb741ac49370ed678857b1f)
This commit is contained in:
+29
-19
@@ -16,6 +16,10 @@ import {
|
||||
export function coreHistory(context) {
|
||||
var dispatch = d3_dispatch('change', 'merge', 'restore', 'undone', 'redone');
|
||||
var lock = utilSessionMutex('lock');
|
||||
|
||||
// restorable if iD not open in another window/tab and a saved history exists in localStorage
|
||||
var _hasUnresolvedRestorableChanges = lock.lock() && !!context.storage(getKey('saved_history'));
|
||||
|
||||
var duration = 150;
|
||||
var _imageryUsed = [];
|
||||
var _photoOverlaysUsed = [];
|
||||
@@ -635,15 +639,32 @@ export function coreHistory(context) {
|
||||
},
|
||||
|
||||
|
||||
lock: function() {
|
||||
return lock.lock();
|
||||
},
|
||||
|
||||
|
||||
unlock: function() {
|
||||
lock.unlock();
|
||||
},
|
||||
|
||||
|
||||
save: function() {
|
||||
if (lock.locked()) context.storage(getKey('saved_history'), history.toJSON() || null);
|
||||
if (lock.locked() &&
|
||||
// don't overwrite existing, unresolved changes
|
||||
!_hasUnresolvedRestorableChanges) {
|
||||
|
||||
context.storage(getKey('saved_history'), history.toJSON() || null);
|
||||
}
|
||||
return history;
|
||||
},
|
||||
|
||||
|
||||
// delete the history version saved in localStorage
|
||||
clearSaved: function() {
|
||||
context.debouncedSave.cancel();
|
||||
if (lock.locked()) {
|
||||
_hasUnresolvedRestorableChanges = false;
|
||||
context.storage(getKey('saved_history'), null);
|
||||
|
||||
// clear the changeset metadata associated with the saved history
|
||||
@@ -655,29 +676,18 @@ export function coreHistory(context) {
|
||||
},
|
||||
|
||||
|
||||
lock: function() {
|
||||
return lock.lock();
|
||||
},
|
||||
|
||||
|
||||
unlock: function() {
|
||||
lock.unlock();
|
||||
},
|
||||
|
||||
|
||||
// is iD not open in another window and it detects that
|
||||
// there's a history stored in localStorage that's recoverable?
|
||||
restorableChanges: function() {
|
||||
return lock.locked() && !!context.storage(getKey('saved_history'));
|
||||
hasRestorableChanges: function() {
|
||||
return _hasUnresolvedRestorableChanges;
|
||||
},
|
||||
|
||||
|
||||
// load history from a version stored in localStorage
|
||||
restore: function() {
|
||||
if (!lock.locked()) return;
|
||||
|
||||
var json = context.storage(getKey('saved_history'));
|
||||
if (json) history.fromJSON(json, true);
|
||||
if (lock.locked()) {
|
||||
_hasUnresolvedRestorableChanges = false;
|
||||
var json = context.storage(getKey('saved_history'));
|
||||
if (json) history.fromJSON(json, true);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import { uiModal } from './modal';
|
||||
|
||||
export function uiRestore(context) {
|
||||
return function(selection) {
|
||||
if (!context.history().lock() || !context.history().restorableChanges()) return;
|
||||
if (!context.history().hasRestorableChanges()) return;
|
||||
|
||||
let modalSelection = uiModal(selection, true);
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ export function uiSplash(context) {
|
||||
// Exception - if there are restorable changes, skip this splash screen.
|
||||
// This is because we currently only support one `uiModal` at a time
|
||||
// and we need to show them `uiRestore`` instead of this one.
|
||||
if (context.history().lock() && context.history().restorableChanges()) return;
|
||||
if (context.history().hasRestorableChanges()) return;
|
||||
|
||||
// If user has not seen this version of the privacy policy, show the splash again.
|
||||
let updateMessage = '';
|
||||
|
||||
Reference in New Issue
Block a user