From 75f33ee58035f15b2ac07f0bd9bea823b960db4a Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Mon, 29 Mar 2021 14:10:20 +0200 Subject: [PATCH] -Nuke the localstorage if it is full --- InitUiElements.ts | 7 ++++--- Logic/Web/LocalStorageSource.ts | 12 +++++++++++- Models/Constants.ts | 2 +- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/InitUiElements.ts b/InitUiElements.ts index 3036984..c1e4b67 100644 --- a/InitUiElements.ts +++ b/InitUiElements.ts @@ -213,6 +213,7 @@ export class InitUiElements { userLayoutParam.setData(layoutToUse.id); return layoutToUse; } catch (e) { + new FixedUiElement("Error: could not parse the custom layout:
" + e).AttachTo("centermessage"); throw e; } @@ -350,8 +351,8 @@ export class InitUiElements { const lonDiff = bounds[0][1] - bounds[1][1] console.warn("Locking the bounds to ", bounds) bm.map.setMaxBounds( - [[ layout.startLat - latDiff, layout.startLon - lonDiff ], - [ layout.startLat + latDiff, layout.startLon + lonDiff ], + [[layout.startLat - latDiff, layout.startLon - lonDiff], + [layout.startLat + latDiff, layout.startLon + lonDiff], ] ); bm.map.setMinZoom(layout.startZoom) @@ -384,7 +385,7 @@ export class InitUiElements { State.state.layerUpdater = updater; const source = new FeaturePipeline(state.filteredLayers, updater, state.layoutToUse, state.changes, state.locationControl); - new ShowDataLayer(source.features, State.state.leafletMap, State.state.layoutToUse); + new ShowDataLayer(source.features, State.state.leafletMap, State.state.layoutToUse); new SelectedFeatureHandler(Hash.hash, State.state.selectedElement, source); diff --git a/Logic/Web/LocalStorageSource.ts b/Logic/Web/LocalStorageSource.ts index 0252ddf..050b124 100644 --- a/Logic/Web/LocalStorageSource.ts +++ b/Logic/Web/LocalStorageSource.ts @@ -1,5 +1,8 @@ import {UIEventSource} from "../UIEventSource"; +/** + * UIEventsource-wrapper around localStorage + */ export class LocalStorageSource { static Get(key: string, defaultValue: string = undefined): UIEventSource { @@ -8,7 +11,14 @@ export class LocalStorageSource { const source = new UIEventSource(saved ?? defaultValue, "localstorage:"+key); source.addCallback((data) => { - localStorage.setItem(key, data); + try{ + localStorage.setItem(key, data); + }catch(e){ + // Probably exceeded the quota with this item! + // Lets nuke everything + localStorage.clear() + } + }); return source; } catch (e) { diff --git a/Models/Constants.ts b/Models/Constants.ts index 44371d6..7d8ba6f 100644 --- a/Models/Constants.ts +++ b/Models/Constants.ts @@ -2,7 +2,7 @@ import { Utils } from "../Utils"; export default class Constants { - public static vNumber = "0.6.3"; + public static vNumber = "0.6.3a"; // The user journey states thresholds when a new feature gets unlocked public static userJourney = {