Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
87c4f6d
initial version
karussell Mar 13, 2023
a6e4321
custom model is kept even when switching back and forth between deskt…
karussell Mar 15, 2023
61ccbd6
fix bug when mobile view is changed to compact view and no new route …
karussell Mar 16, 2023
b697750
move CustomModelBox into SettingsBox but outside of settingsTable
karussell Mar 16, 2023
7b7839a
minor -> warn
karussell Mar 16, 2023
c476d81
minor css fix
karussell Mar 17, 2023
63ea078
make settings css better fit the rest
karussell Mar 17, 2023
aee208b
1. URL with custom_model should trigger a routing request with it; 2.…
karussell Mar 18, 2023
7ef455e
Merge branch 'master' into gear_as_setting_button
karussell Mar 18, 2023
96108d7
tricky to fix error 'Cannot use import statement outside a module' in…
karussell Mar 19, 2023
885a2c6
Merge branch 'master' into gear_as_setting_button
karussell Mar 21, 2023
d1e707a
remove CustomModel from QueryStore state
karussell Mar 21, 2023
9ed5ed1
Merge branch 'master' into gear_as_setting_button
karussell Mar 21, 2023
f57ac3e
formatting
karussell Mar 21, 2023
35f091c
Merge branch 'master' into gear_as_setting_button
karussell Mar 21, 2023
34b091d
revert change with SettingsContext to use ShowDistanceInMilesContext
karussell Mar 22, 2023
1657925
format and clean up imports
easbar Mar 22, 2023
78b25ca
show error message if invalid custom model (not possible at Settings …
karussell Mar 22, 2023
6625911
not many benefits to use validateJson as e.g. encoded values not yet …
karussell Mar 22, 2023
fe88161
revert commit 96108d7e07af7811bdf908d32b8fc4f6804c3e89
karussell Mar 22, 2023
ddc4015
Merge branch 'master' into gear_as_setting_button
karussell Mar 22, 2023
e3ca24d
remove TODO NOW
karussell Mar 22, 2023
cc658e3
Use string to represent custom model state (#320)
easbar Mar 23, 2023
d1f245b
no shadow, use text instead
karussell Mar 23, 2023
bcc0d55
i18n: update
karussell Mar 23, 2023
b6284f8
Merge branch 'master' into gear_as_setting_button
karussell Mar 23, 2023
d9df268
separate custom model box and settings box and use gear as indicator …
karussell Mar 23, 2023
f04c3be
format
karussell Mar 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,20 @@ import ContextMenu from '@/layers/ContextMenu'
import usePathDetailsLayer from '@/layers/UsePathDetailsLayer'
import { Map } from 'ol'
import { getMap } from '@/map/map'
import CustomModelBox from '@/sidebar/CustomModelBox'
import useRoutingGraphLayer from '@/layers/UseRoutingGraphLayer'
import useUrbanDensityLayer from '@/layers/UseUrbanDensityLayer'
import useMapBorderLayer from '@/layers/UseMapBorderLayer'
import { ShowDistanceInMilesContext } from '@/ShowDistanceInMilesContext'
import RoutingProfiles from '@/sidebar/search/routingProfiles/RoutingProfiles'
import MapPopups from '@/map/MapPopups'
import Menu from '@/sidebar/menu.svg'
import Cross from '@/sidebar/times-solid.svg'
import PlainButton from '@/PlainButton'
import useAreasLayer from '@/layers/UseAreasLayer'
import SettingsBox from '@/sidebar/SettingsBox'
import Dispatcher from '@/stores/Dispatcher'
import { ToggleShowSettings } from '@/actions/Actions'
import CustomModelBox from '@/sidebar/CustomModelBox'
import { SettingsContext } from '@/stores/SettingsStore'

export const POPUP_CONTAINER_ID = 'popup-container'
export const SIDEBAR_CONTENT_ID = 'sidebar-content'
Expand Down Expand Up @@ -99,15 +102,15 @@ export default function App() {
// our different map layers
useBackgroundLayer(map, mapOptions.selectedStyle)
useMapBorderLayer(map, info.bbox)
useAreasLayer(map, query.customModelEnabled && query.customModelValid ? query.customModel?.areas! : null)
useAreasLayer(map, settings.customModelEnabled && settings.customModelValid ? query.customModel?.areas! : null)
useRoutingGraphLayer(map, mapOptions.routingGraphEnabled)
useUrbanDensityLayer(map, mapOptions.urbanDensityEnabled)
usePathsLayer(map, route.routingResult.paths, route.selectedPath)
useQueryPointsLayer(map, query.queryPoints)
usePathDetailsLayer(map, pathDetails)
const isSmallScreen = useMediaQuery({ query: '(max-width: 44rem)' })
return (
<ShowDistanceInMilesContext.Provider value={settings.showDistanceInMiles}>
<SettingsContext.Provider value={settings}>
<div className={styles.appWrapper}>
<MapPopups map={map} pathDetails={pathDetails} mapFeatures={mapFeatures} />
<ContextMenu map={map} route={route} queryPoints={query.queryPoints} />
Expand All @@ -131,7 +134,7 @@ export default function App() {
/>
)}
</div>
</ShowDistanceInMilesContext.Provider>
</SettingsContext.Provider>
)
}

Expand All @@ -157,13 +160,10 @@ function LargeScreenLayout({ query, route, map, error, mapOptions, encodedValues
<RoutingProfiles
routingProfiles={query.profiles}
selectedProfile={query.routingProfile}
customModelAllowed={true}
customModelEnabled={query.customModelEnabled}
openSettingsHandle={() => Dispatcher.dispatch(new ToggleShowSettings())}
/>
<CustomModelBox
enabled={query.customModelEnabled}
<SettingsBox
encodedValues={encodedValues}
initialCustomModelStr={query.initialCustomModelStr}
queryOngoing={query.currentRequest.subRequests[0]?.state === RequestState.SENT}
/>
<Search points={query.queryPoints} />
Expand Down Expand Up @@ -201,11 +201,11 @@ function LargeScreenLayout({ query, route, map, error, mapOptions, encodedValues
)
}

function SmallScreenLayout({ query, route, map, error, mapOptions }: LayoutProps) {
function SmallScreenLayout({ query, route, map, error, mapOptions, encodedValues }: LayoutProps) {
return (
<>
<div className={styles.smallScreenSidebar}>
<MobileSidebar query={query} route={route} error={error} />
<MobileSidebar query={query} route={route} error={error} encodedValues={encodedValues} />
</div>
<div className={styles.smallScreenMap}>
<MapComponent map={map} />
Expand Down
17 changes: 13 additions & 4 deletions src/NavBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@ import { window } from '@/Window'
import QueryStore, { Coordinate, QueryPoint, QueryPointType, QueryStoreState } from '@/stores/QueryStore'
import MapOptionsStore, { MapOptionsStoreState } from './stores/MapOptionsStore'
import { getApi } from '@/api/Api'
import SettingsStore from '@/stores/SettingsStore'

export default class NavBar {
private readonly queryStore: QueryStore
private readonly mapStore: MapOptionsStore
private readonly settingsStore: SettingsStore
private ignoreStateUpdates = false

constructor(queryStore: QueryStore, mapStore: MapOptionsStore) {
constructor(queryStore: QueryStore, mapStore: MapOptionsStore, settingsStore: SettingsStore) {
this.queryStore = queryStore
this.mapStore = mapStore
this.settingsStore = settingsStore
window.addEventListener('popstate', async () => await this.updateStateFromUrl())
}

Expand All @@ -26,7 +29,12 @@ export default class NavBar {
this.mapStore.register(() => this.updateUrlFromState())
}

private static createUrl(baseUrl: string, queryStoreState: QueryStoreState, mapState: MapOptionsStoreState) {
private static createUrl(
baseUrl: string,
queryStoreState: QueryStoreState,
mapState: MapOptionsStoreState,
addCustomModel: boolean
) {
const result = new URL(baseUrl)
if (queryStoreState.queryPoints.filter(point => point.isInitialized).length > 0) {
queryStoreState.queryPoints
Expand All @@ -36,7 +44,7 @@ export default class NavBar {

result.searchParams.append('profile', queryStoreState.routingProfile.name)
result.searchParams.append('layer', mapState.selectedStyle.name)
if (queryStoreState.customModelEnabled && queryStoreState.customModel && queryStoreState.customModelValid)
if (addCustomModel && queryStoreState.customModel)
result.searchParams.append('custom_model', JSON.stringify(queryStoreState.customModel))

return result
Expand Down Expand Up @@ -156,7 +164,8 @@ export default class NavBar {
return NavBar.createUrl(
window.location.origin + window.location.pathname,
this.queryStore.state,
this.mapStore.state
this.mapStore.state,
this.settingsStore.state.customModelEnabled && this.settingsStore.state.customModelValid
).toString()
}

Expand Down
2 changes: 0 additions & 2 deletions src/ShowDistanceInMilesContext.ts

This file was deleted.

2 changes: 2 additions & 0 deletions src/actions/Actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,5 @@ export class InstructionClicked implements Action {
}

export class ToggleDistanceUnits implements Action {}

export class ToggleShowSettings implements Action {}
7 changes: 4 additions & 3 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ const apiKey = url.searchParams.has('key') ? url.searchParams.get('key') : confi
setApi(config.routingApi, config.geocodingApi, apiKey || '')

const initialCustomModelStr = url.searchParams.get('custom_model')
const queryStore = new QueryStore(getApi(), initialCustomModelStr)
const settingsStore = new SettingsStore(initialCustomModelStr)
const queryStore = new QueryStore(getApi(), settingsStore)
const routeStore = new RouteStore(queryStore)

setStores({
settingsStore: new SettingsStore(),
settingsStore: settingsStore,
queryStore: queryStore,
routeStore: routeStore,
infoStore: new ApiInfoStore(),
Expand All @@ -72,7 +73,7 @@ const smallScreenMediaQuery = window.matchMedia('(max-width: 44rem)')
const mapActionReceiver = new MapActionReceiver(getMap(), routeStore, () => smallScreenMediaQuery.matches)
Dispatcher.register(mapActionReceiver)

const navBar = new NavBar(getQueryStore(), getMapOptionsStore())
const navBar = new NavBar(getQueryStore(), getMapOptionsStore(), getSettingsStore())

// get infos about the api as soon as possible
getApi()
Expand Down
4 changes: 2 additions & 2 deletions src/layers/PathDetailPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { useContext } from 'react'
import styles from '@/layers/DefaultMapPopup.module.css'
import { PathDetailsStoreState } from '@/stores/PathDetailsStore'
import { metersToText } from '@/Converters'
import { ShowDistanceInMilesContext } from '@/ShowDistanceInMilesContext'
import MapPopup from '@/layers/MapPopup'
import { Map } from 'ol'
import { SettingsContext } from '@/stores/SettingsStore'

interface PathDetailPopupProps {
map: Map
Expand All @@ -15,7 +15,7 @@ interface PathDetailPopupProps {
* The popup shown along the selected route when we hover the path detail/elevation graph
*/
export default function PathDetailPopup({ map, pathDetails }: PathDetailPopupProps) {
const showDistanceInMiles = useContext(ShowDistanceInMilesContext)
const { showDistanceInMiles } = useContext(SettingsContext)
return (
// todo: use createMapMarker from heightgraph?
// {createMapMarker(point.elevation, point.description, showDistanceInMiles)}
Expand Down
4 changes: 2 additions & 2 deletions src/pathDetails/PathDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { PathDetailsElevationSelected, PathDetailsHover, PathDetailsRangeSelecte
import QueryStore, { Coordinate, QueryPointType } from '@/stores/QueryStore'
import { Position } from 'geojson'
import { calcDist } from '@/distUtils'
import { ShowDistanceInMilesContext } from '@/ShowDistanceInMilesContext'
import { SettingsContext } from '@/stores/SettingsStore'

interface PathDetailsProps {
selectedPath: Path
Expand Down Expand Up @@ -52,7 +52,7 @@ export default function ({ selectedPath }: PathDetailsProps) {
graph?.setData(pathDetailsData.data, pathDetailsData.mappings)
}, [selectedPath, graph])

const showDistanceInMiles = useContext(ShowDistanceInMilesContext)
const { showDistanceInMiles } = useContext(SettingsContext)
useEffect(() => {
graph?.setImperial(showDistanceInMiles)
graph?.redraw()
Expand Down
Loading