Interactive interface for browsing global, full-resolution satellite imagery
store recent layers in localStorage
Jason Kent4dd5a73da388
diff --git a/web/js/modules/layers/actions.js b/web/js/modules/layers/actions.jsindex 1f90c024f..91dbceee1 100644--- a/web/js/modules/layers/actions.js+++ b/web/js/modules/layers/actions.js@@ -7,6 +7,7 @@ import {getLayers as getLayersSelector,activateLayersForEventCategory as activateLayersForEventCategorySelector,} from './selectors';+import updateRecentLayers from './util';import {RESET_LAYERS,ADD_LAYER,@@ -56,7 +57,7 @@ export function addLayer(id, spec) {event: 'layer_added',layers: { id },});-+ updateRecentLayers(id);return (dispatch, getState) => {const state = getState();const { layers, compare, proj } = state;diff --git a/web/js/modules/layers/util.js b/web/js/modules/layers/util.jsindex 7ed491f14..3316d4d49 100644--- a/web/js/modules/layers/util.js+++ b/web/js/modules/layers/util.js@@ -17,6 +17,7 @@ import { addLayer, resetLayers } from './selectors';import { getPaletteAttributeArray } from '../palettes/util';import { getVectorStyleAttributeArray } from '../vector-styles/util';import util from '../../util/util';+import safeLocalStorage from '../../util/local-storage';export function getOrbitTrackTitle(def) {const { track } = def;@@ -1249,3 +1250,16 @@ export const hasNonClickableVectorLayer = (activeLayers, mapRes) => {}return isNonClickableVectorLayer;};++// safeLocalStorage.removeItem(lsKey);+export const updateRecentLayers = (id) => {+ const { recentLayersKey: key } = safeLocalStorage.keys;+ const recentLayersJson = safeLocalStorage.getItem(key);+ let recentLayers = JSON.parse(recentLayersJson) || [];+ if (recentLayers.length >= 10) {+ recentLayers = recentLayers.slice(1, 10);+ }+ recentLayers.push(id);+ console.table(recentLayers);+ safeLocalStorage.setItem(key, JSON.stringify(recentLayers));+};