From 3a5a336a7302b192960d9ab7a938b9053b4fd25d Mon Sep 17 00:00:00 2001 From: TacosTonight Date: Tue, 23 May 2023 22:23:19 -0700 Subject: [PATCH 1/5] feat: remember last date --- src/components/Scrubber.vue | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/components/Scrubber.vue b/src/components/Scrubber.vue index 2e79ea8b..d49f298d 100755 --- a/src/components/Scrubber.vue +++ b/src/components/Scrubber.vue @@ -281,6 +281,9 @@ export default { } }, mounted () { + if (window.localStorage.getItem('activeEvent')) { + this.$store.commit('selectEvent', this.$store.state.mappings.events[localStorage.getItem('activeEvent')]) + } if (this.activeEvent !== null) { setTimeout(() => this.scrollToEvent(this.activeEvent), 1500) } else { @@ -475,6 +478,7 @@ export default { selectEvent (event) { this.$store.commit('selectEvent', event) this.scrollToEvent(event) + window.localStorage.setItem('activeEvent', event.id) }, scrollToEvent (event) { this.$nextTick(() => { From cac44b53ceacc1daef9b000166d909f87815a1ba Mon Sep 17 00:00:00 2001 From: TacosTonight Date: Wed, 14 Jun 2023 00:45:07 -0700 Subject: [PATCH 2/5] feat: remember activeLayers --- src/components/map/Map.vue | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/components/map/Map.vue b/src/components/map/Map.vue index 6b94b4c3..e5fadb8f 100755 --- a/src/components/map/Map.vue +++ b/src/components/map/Map.vue @@ -99,6 +99,7 @@ export default { layersActive: { handler (layersActive) { this.updateLayers(layersActive) + window.localStorage.setItem('layersActive', JSON.stringify(layersActive)) }, deep: true }, @@ -130,6 +131,13 @@ export default { return } + if (window.localStorage.getItem('layersActive')) { + const layersActive = JSON.parse(localStorage.getItem('layersActive')) + Object.entries(layersActive).forEach(([layer, value]) => { + this.$store.commit('toggleLayer', { layer, value }) + }) + } + // #ifdef MAP_DEBUG this.stats = new Stats() this.stats.dom.style.width = '80px' From 8befd164cb4cab4512377d5ad82b4472be26703f Mon Sep 17 00:00:00 2001 From: TacosTonight Date: Wed, 14 Jun 2023 01:35:09 -0700 Subject: [PATCH 3/5] fix: ensure setupScene is run first before loading localStorage activeLayer --- src/components/map/Map.vue | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/components/map/Map.vue b/src/components/map/Map.vue index e5fadb8f..4ca54f84 100755 --- a/src/components/map/Map.vue +++ b/src/components/map/Map.vue @@ -131,13 +131,6 @@ export default { return } - if (window.localStorage.getItem('layersActive')) { - const layersActive = JSON.parse(localStorage.getItem('layersActive')) - Object.entries(layersActive).forEach(([layer, value]) => { - this.$store.commit('toggleLayer', { layer, value }) - }) - } - // #ifdef MAP_DEBUG this.stats = new Stats() this.stats.dom.style.width = '80px' @@ -147,6 +140,14 @@ export default { this.loadTextures() .then(this.setupScene) + .then(() => { + if (window.localStorage.getItem('layersActive')) { + const layersActive = JSON.parse(localStorage.getItem('layersActive')) + Object.entries(layersActive).forEach(([layer, value]) => { + this.$store.commit('toggleLayer', { layer, value }) + }) + } + }) .then(() => { this.$el.prepend(this.renderer.domElement) From 808738de45ddd3b0527d184d15412375e612ad92 Mon Sep 17 00:00:00 2001 From: TacosTonight Date: Wed, 14 Jun 2023 20:07:06 -0700 Subject: [PATCH 4/5] feat: move writing to local storage into store mutation --- src/components/Scrubber.vue | 1 - src/components/map/Map.vue | 1 - src/store/index.js | 3 +++ 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/components/Scrubber.vue b/src/components/Scrubber.vue index d49f298d..b1c43a31 100755 --- a/src/components/Scrubber.vue +++ b/src/components/Scrubber.vue @@ -478,7 +478,6 @@ export default { selectEvent (event) { this.$store.commit('selectEvent', event) this.scrollToEvent(event) - window.localStorage.setItem('activeEvent', event.id) }, scrollToEvent (event) { this.$nextTick(() => { diff --git a/src/components/map/Map.vue b/src/components/map/Map.vue index 4ca54f84..f457bef4 100755 --- a/src/components/map/Map.vue +++ b/src/components/map/Map.vue @@ -99,7 +99,6 @@ export default { layersActive: { handler (layersActive) { this.updateLayers(layersActive) - window.localStorage.setItem('layersActive', JSON.stringify(layersActive)) }, deep: true }, diff --git a/src/store/index.js b/src/store/index.js index 748fae41..7b06b1d8 100755 --- a/src/store/index.js +++ b/src/store/index.js @@ -209,9 +209,11 @@ const locationsByMapId = Object.values(mappings.locations).filter(location => lo const mutations = { selectEvent (state, event) { state.activeEvent = event + window.localStorage.setItem('activeEvent', event.id) }, unselectEvent (state) { state.activeEvent = null + window.localStorage.setItem('activeEvent', '') }, enableTag (state, tag) { const index = state.filter.tags.indexOf(tag) @@ -256,6 +258,7 @@ const mutations = { }, toggleLayer (state, { layer, value }) { state.layersActive[layer] = value + window.localStorage.setItem('layersActive', JSON.stringify(state.layersActive)) }, openCalendarGuide (state) { state.calendarGuideOpen = true From f09b476599c3ff6945936669a707750131020a62 Mon Sep 17 00:00:00 2001 From: TacosTonight Date: Thu, 15 Jun 2023 00:01:09 -0700 Subject: [PATCH 5/5] feat: moved local storage access into app mounted and added local storage write for filter --- src/App.vue | 14 ++++++++++++++ src/components/Scrubber.vue | 3 --- src/components/map/Map.vue | 8 -------- src/store/index.js | 8 +++++++- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/App.vue b/src/App.vue index a0dd5b35..fc6c0330 100755 --- a/src/App.vue +++ b/src/App.vue @@ -135,6 +135,20 @@ export default { } } }, + mounted () { + if (window.localStorage.getItem('activeEvent')) { + this.$store.commit('selectEvent', this.$store.state.mappings.events[localStorage.getItem('activeEvent')]) + } + if (window.localStorage.getItem('layersActive')) { + const layersActive = JSON.parse(localStorage.getItem('layersActive')) + Object.entries(layersActive).forEach(([layer, value]) => { + this.$store.commit('toggleLayer', { layer, value }) + }) + } + if (window.localStorage.getItem('filter')) { + this.$store.commit('updateFilter', JSON.parse(localStorage.getItem('filter'))) + } + }, methods: { onReady () { this.ready = true diff --git a/src/components/Scrubber.vue b/src/components/Scrubber.vue index b1c43a31..2e79ea8b 100755 --- a/src/components/Scrubber.vue +++ b/src/components/Scrubber.vue @@ -281,9 +281,6 @@ export default { } }, mounted () { - if (window.localStorage.getItem('activeEvent')) { - this.$store.commit('selectEvent', this.$store.state.mappings.events[localStorage.getItem('activeEvent')]) - } if (this.activeEvent !== null) { setTimeout(() => this.scrollToEvent(this.activeEvent), 1500) } else { diff --git a/src/components/map/Map.vue b/src/components/map/Map.vue index f457bef4..6b94b4c3 100755 --- a/src/components/map/Map.vue +++ b/src/components/map/Map.vue @@ -139,14 +139,6 @@ export default { this.loadTextures() .then(this.setupScene) - .then(() => { - if (window.localStorage.getItem('layersActive')) { - const layersActive = JSON.parse(localStorage.getItem('layersActive')) - Object.entries(layersActive).forEach(([layer, value]) => { - this.$store.commit('toggleLayer', { layer, value }) - }) - } - }) .then(() => { this.$el.prepend(this.renderer.domElement) diff --git a/src/store/index.js b/src/store/index.js index 7b06b1d8..af296181 100755 --- a/src/store/index.js +++ b/src/store/index.js @@ -209,12 +209,15 @@ const locationsByMapId = Object.values(mappings.locations).filter(location => lo const mutations = { selectEvent (state, event) { state.activeEvent = event - window.localStorage.setItem('activeEvent', event.id) + window.localStorage.setItem('activeEvent', state.activeEvent.id) }, unselectEvent (state) { state.activeEvent = null window.localStorage.setItem('activeEvent', '') }, + updateFilter (state, filter) { + state.filter = filter + }, enableTag (state, tag) { const index = state.filter.tags.indexOf(tag) @@ -223,6 +226,7 @@ const mutations = { } mutations.disableTagSeparation(state, tag) + window.localStorage.setItem('filter', JSON.stringify(state.filter)) }, disableTag (state, tag) { if (!state.filter.tags.includes(tag)) { @@ -230,6 +234,7 @@ const mutations = { } mutations.disableTagSeparation(state, tag) + window.localStorage.setItem('filter', JSON.stringify(state.filter)) }, enableTagSeparation (state, tag) { mutations.enableTag(state, tag) @@ -239,6 +244,7 @@ const mutations = { } state.filter.latestSeparatedTag = tag + window.localStorage.setItem('filter', JSON.stringify(state.filter)) }, disableTagSeparation (state, tag) { const index = state.filter.separateTags.indexOf(tag)