From 442a7f612c7569ffda429a610815c51823860141 Mon Sep 17 00:00:00 2001 From: lukasmartinelli Date: Wed, 21 Sep 2016 08:34:48 +0200 Subject: [PATCH] Support resetting styles --- src/app.jsx | 6 ++++++ src/settings.jsx | 7 ++++++- src/stylestore.js | 10 ++++++++++ src/workspace.jsx | 2 ++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/app.jsx b/src/app.jsx index 1b8988a4..855093f1 100644 --- a/src/app.jsx +++ b/src/app.jsx @@ -34,6 +34,11 @@ export default class App extends React.Component { } } + onReset() { + this.styleStore.purge() + loadDefaultStyle(mapStyle => this.onStyleUpload(mapStyle)) + } + getChildContext() { return { rebass: theme, @@ -98,6 +103,7 @@ export default class App extends React.Component { /> + } diff --git a/src/stylestore.js b/src/stylestore.js index 834b3498..85db8b45 100644 --- a/src/stylestore.js +++ b/src/stylestore.js @@ -91,6 +91,16 @@ export class StyleStore { this.mapStyles = loadStoredStyles() } + // Delete entire style history + purge() { + for (let i = 0; i < window.localStorage.length; i++) { + const key = window.localStorage.key(i) + if(key.startsWith(storagePrefix)) { + window.localStorage.removeItem(key) + } + } + } + // Find the last edited style latestStyle() { if(this.mapStyles.length === 0) return emptyStyle diff --git a/src/workspace.jsx b/src/workspace.jsx index 7f9ff5be..63c6a89a 100644 --- a/src/workspace.jsx +++ b/src/workspace.jsx @@ -14,6 +14,7 @@ export class WorkspaceDrawer extends React.Component { workContext: React.PropTypes.oneOf(['layers', 'settings', 'sources']).isRequired, accessToken: React.PropTypes.string, onAccessTokenChanged: React.PropTypes.func, + onReset: React.PropTypes.func, } onLayersChanged(changedLayers) { @@ -39,6 +40,7 @@ export class WorkspaceDrawer extends React.Component { if(this.props.workContext === "settings") { workspaceContent =