Skip to content

Commit

Permalink
Revert 'cosmetics: avoid layer and profile parameter on first load if…
Browse files Browse the repository at this point in the history
… equal to default' fixes #395
  • Loading branch information
karussell committed Jun 15, 2024
1 parent 651952a commit c9ef18d
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions src/NavBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import QueryStore, {
} from '@/stores/QueryStore'
import MapOptionsStore, { MapOptionsStoreState } from './stores/MapOptionsStore'
import { getApi } from '@/api/Api'
import config from 'config'

export default class NavBar {
private readonly queryStore: QueryStore
Expand All @@ -28,28 +27,21 @@ export default class NavBar {

async startSyncingUrlWithAppState() {
// our first history entry shall be the one that we end up with when the app loads for the first time
window.history.replaceState(null, '', this.createUrlFromState(true))
window.history.replaceState(null, '', this.createUrlFromState())
this.queryStore.register(() => this.updateUrlFromState())
this.mapStore.register(() => this.updateUrlFromState())
}

private static createUrl(
baseUrl: string,
queryStoreState: QueryStoreState,
mapState: MapOptionsStoreState,
first: boolean
) {
private static createUrl(baseUrl: string, queryStoreState: QueryStoreState, mapState: MapOptionsStoreState) {
const result = new URL(baseUrl)
if (queryStoreState.queryPoints.filter(point => point.isInitialized).length > 0) {
queryStoreState.queryPoints
.map(point => (!point.isInitialized ? '' : NavBar.pointToParam(point)))
.forEach(pointAsString => result.searchParams.append('point', pointAsString))
}

if (!first || queryStoreState.routingProfile.name != Object.keys(config.profiles ?? {})[0])
result.searchParams.append('profile', queryStoreState.routingProfile.name)
if (!first || mapState.selectedStyle.name != config.defaultTiles)
result.searchParams.append('layer', mapState.selectedStyle.name)
result.searchParams.append('profile', queryStoreState.routingProfile.name)
result.searchParams.append('layer', mapState.selectedStyle.name)
if (queryStoreState.customModelEnabled)
result.searchParams.append('custom_model', queryStoreState.customModelStr.replace(/\s+/g, ''))

Expand Down Expand Up @@ -166,16 +158,15 @@ export default class NavBar {

public updateUrlFromState() {
if (this.ignoreStateUpdates) return
const newHref = this.createUrlFromState(false)
const newHref = this.createUrlFromState()
if (newHref !== window.location.href) window.history.pushState(null, '', newHref)
}

private createUrlFromState(first: boolean) {
private createUrlFromState() {
return NavBar.createUrl(
window.location.origin + window.location.pathname,
this.queryStore.state,
this.mapStore.state,
first
this.mapStore.state
).toString()
}

Expand Down

0 comments on commit c9ef18d

Please sign in to comment.