show an error if local storage is full

This commit is contained in:
Kyle Hensel
2021-09-30 19:40:55 +13:00
parent 021107cb81
commit d08c09f5ee
5 changed files with 17 additions and 3 deletions

View File

@@ -576,6 +576,7 @@ en:
offline: The OpenStreetMap API is offline. Your edits are safe locally. Please come back later.
readonly: The OpenStreetMap API is currently read-only. You can continue editing, but must wait to save your changes.
rateLimit: The OpenStreetMap API is limiting anonymous connections. You can fix this by logging in.
local_storage_full: You have made too many edits to back up. Consider saving your changes now.
retry: Retry
commit:
title: Upload to OpenStreetMap

File diff suppressed because one or more lines are too long

View File

@@ -15,7 +15,7 @@ import {
export function coreHistory(context) {
var dispatch = d3_dispatch('reset', 'change', 'merge', 'restore', 'undone', 'redone');
var dispatch = d3_dispatch('reset', 'change', 'merge', 'restore', 'undone', 'redone', 'storage_error');
var lock = utilSessionMutex('lock');
// restorable if iD not open in another window/tab and a saved history exists in localStorage
@@ -659,8 +659,9 @@ export function coreHistory(context) {
if (lock.locked() &&
// don't overwrite existing, unresolved changes
!_hasUnresolvedRestorableChanges) {
const success = prefs(getKey('saved_history'), history.toJSON() || null);
prefs(getKey('saved_history'), history.toJSON() || null);
if (!success) dispatch.call('storage_error');
}
return history;
},

View File

@@ -16,18 +16,25 @@ _storage = _storage || (() => {
// corePreferences is an interface for persisting basic key-value strings
// within and between iD sessions on the same site.
//
/**
* @param {string} k
* @param {string?} v
* @returns {boolean} true if the action succeeded
*/
function corePreferences(k, v) {
try {
if (arguments.length === 1) return _storage.getItem(k);
else if (v === null) _storage.removeItem(k);
else _storage.setItem(k, v);
return true;
} catch (e) {
/* eslint-disable no-console */
if (typeof console !== 'undefined') {
console.error('localStorage quota exceeded');
}
/* eslint-enable no-console */
return false;
}
}

View File

@@ -69,6 +69,11 @@ export function uiStatus(context) {
osm.on('apiStatusChange.uiStatus', update);
context.history().on('storage_error', () => {
selection.html(t.html('osm_api_status.message.local_storage_full'));
selection.attr('class', 'api-status error');
});
// reload the status periodically regardless of other factors
window.setInterval(function() {
osm.reloadApiStatus();