From 88a4a191bb6c9357d76cabd293b972efeff514aa Mon Sep 17 00:00:00 2001 From: Eric Brelsford Date: Thu, 30 Nov 2023 22:33:10 -0500 Subject: [PATCH] Fix stateful URLs --- vacs-map-app/src/App.vue | 3 --- vacs-map-app/src/main.js | 5 ++--- vacs-map-app/src/store-plugins/query.js | 7 +------ vacs-map-app/src/stores/filters.js | 4 +++- 4 files changed, 6 insertions(+), 13 deletions(-) diff --git a/vacs-map-app/src/App.vue b/vacs-map-app/src/App.vue index 74510e5..cc4df7d 100644 --- a/vacs-map-app/src/App.vue +++ b/vacs-map-app/src/App.vue @@ -27,9 +27,6 @@ onMounted(() => { cropYieldsStore.load() cropInformationStore.load() - // initialize so pages load - filtersStore.selectedCrop = filtersStore.availableCrops[0] - window.addEventListener('resize', documentHeight) documentHeight }) diff --git a/vacs-map-app/src/main.js b/vacs-map-app/src/main.js index 8dc351a..3159498 100644 --- a/vacs-map-app/src/main.js +++ b/vacs-map-app/src/main.js @@ -14,6 +14,8 @@ import QueryPlugin from '@/store-plugins/query' import { getActivePinia } from 'pinia' const app = createApp(App) +app.use(createPinia()) +getActivePinia().use(QueryPlugin) const routes = [ { path: '/', component: LandingPage }, @@ -30,8 +32,5 @@ const router = VueRouter.createRouter({ routes // short for `routes: routes` }) -app.use(createPinia()) app.use(router) app.mount('#app') - -getActivePinia().use(QueryPlugin) diff --git a/vacs-map-app/src/store-plugins/query.js b/vacs-map-app/src/store-plugins/query.js index ee24637..656dbb3 100644 --- a/vacs-map-app/src/store-plugins/query.js +++ b/vacs-map-app/src/store-plugins/query.js @@ -16,11 +16,6 @@ const toPersist = [ key: 'selectedModel', outputKey: 'model' }, - { - store: 'mapExplore', - key: 'selectedMap', - outputKey: 'map' - } ] const getParams = (pinia) => { @@ -63,7 +58,7 @@ export default ({ pinia, store }) => { if (Object.keys(params).length > 0) { if (window) { const newUrl = location.hash.split('?')[0] + `?${qs.stringify(params)}` - window.history.replaceState(null, '', newUrl) + window.history.replaceState({ ...window.history.state }, '', newUrl) } } }) diff --git a/vacs-map-app/src/stores/filters.js b/vacs-map-app/src/stores/filters.js index 186e703..85af63f 100644 --- a/vacs-map-app/src/stores/filters.js +++ b/vacs-map-app/src/stores/filters.js @@ -55,7 +55,9 @@ export const useFiltersStore = defineStore('filters', () => { .map((k) => k.split('_').slice(2).join('_')) ) ).sort() - selectedModel.value = availableModels.value[0] + if (!selectedModel.value) { + selectedModel.value = availableModels.value[0] + } }) const cropInformationStore = useCropInformationStore()