Skip to content

Commit

Permalink
Merge pull request #109 from earthrise-media/urls-replace-state
Browse files Browse the repository at this point in the history
Fix stateful URLs
  • Loading branch information
Martin Bernard authored Dec 1, 2023
2 parents a30c29d + 88a4a19 commit 6cc31c6
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 13 deletions.
3 changes: 0 additions & 3 deletions vacs-map-app/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ onMounted(() => {
cropYieldsStore.load()
cropInformationStore.load()
// initialize so pages load
filtersStore.selectedCrop = filtersStore.availableCrops[0]
window.addEventListener('resize', documentHeight)
documentHeight
})
Expand Down
5 changes: 2 additions & 3 deletions vacs-map-app/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand All @@ -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)
7 changes: 1 addition & 6 deletions vacs-map-app/src/store-plugins/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ const toPersist = [
key: 'selectedModel',
outputKey: 'model'
},
{
store: 'mapExplore',
key: 'selectedMap',
outputKey: 'map'
}
]

const getParams = (pinia) => {
Expand Down Expand Up @@ -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)
}
}
})
Expand Down
4 changes: 3 additions & 1 deletion vacs-map-app/src/stores/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 6cc31c6

Please sign in to comment.