Skip to content

Mobile batch results #339

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 51 commits into from
Apr 13, 2021
Merged
Show file tree
Hide file tree
Changes from 47 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
ec0662d
feat(mobile/batch-results-screen): Add mobile batch results screen.
binh-dam-ibigroup Mar 3, 2021
d35ce7f
refactor(mobile/BatchResultsScreen): Clean up code.
binh-dam-ibigroup Mar 3, 2021
b1a84b6
refactor(BatchResultsScreen): Fix fitting itinerary after expanding map.
binh-dam-ibigroup Mar 4, 2021
9c21e13
refactor(BatchResultsScreen): Tweak styles.
binh-dam-ibigroup Mar 4, 2021
90be15a
refactor(mobile/ResultsHeaderAndError): Extract component. Refactors.
binh-dam-ibigroup Mar 5, 2021
50d8d23
style(mobile/*results*): Tweak comments and sort props and imports.
binh-dam-ibigroup Mar 5, 2021
e802be6
refactor(batch results): Mention component is required, fix typo.
binh-dam-ibigroup Mar 12, 2021
c10d7ca
fix(narrative-itineraries.js, default-itinerary.js): Added setActiveL…
Mar 11, 2021
edea628
fix(default-itinerary.js): Removed some unused code.
Mar 11, 2021
100c1d6
fix(BatchResultsScreen): Fix leg focus, address some PR comments.
binh-dam-ibigroup Mar 23, 2021
df664e0
refactor(BatchResultsScreen): Show result screen with correct #itins …
binh-dam-ibigroup Mar 23, 2021
79488a8
refactor(mobile/main): Show mobile results screen on plan.
binh-dam-ibigroup Mar 23, 2021
4a1d32a
refactor(ResultsError): Split results header and error section.
binh-dam-ibigroup Mar 23, 2021
d615fd8
style(ResultsScreen): Commit indents
binh-dam-ibigroup Mar 23, 2021
22beb2c
style(mobile/main): Fix indent
binh-dam-ibigroup Mar 23, 2021
15329fe
refactor(BoundsUpdatingOverlay): Remove fit bounds mobile restriction.
binh-dam-ibigroup Mar 24, 2021
fc76d3e
refactor(BatchResultsScreen): Investigate imperative resizing.
binh-dam-ibigroup Mar 24, 2021
2e7757c
refactor(map/default-map): Use key prop to force transitive remount o…
binh-dam-ibigroup Mar 24, 2021
557bfc7
refactor(BatchResultsScreen): Refactor, tweak split height.
binh-dam-ibigroup Mar 24, 2021
3edc3d4
refactor(BatchResultScreen): Move itin state to URL param, remove sta…
binh-dam-ibigroup Mar 24, 2021
9e71d59
refactor(mobile/BatchResultsScreen): Tweak layout for no-results.
binh-dam-ibigroup Mar 25, 2021
922e28c
refactor(NarrativeItineraries): Initialize component with itin view U…
binh-dam-ibigroup Mar 25, 2021
2b77be6
refactor(BoundsUpdatingOverlay): Reset transitive on leg click from e…
binh-dam-ibigroup Mar 25, 2021
ef95547
refactor(BoundsUpdatingOverlay): Fix lint
binh-dam-ibigroup Mar 25, 2021
794aeaf
docs: Update comments from PR reviews.
binh-dam-ibigroup Mar 30, 2021
b1ab768
refactor(BoundsUpdatingOverlay): Revert block regarding #133.
binh-dam-ibigroup Mar 30, 2021
b738bd2
refactor(BoundsUpdatingOverlay): Move code per PR comment
binh-dam-ibigroup Mar 30, 2021
19f0569
refactor(BatchResultsScreen): Replace showDetails state with itinerar…
binh-dam-ibigroup Mar 30, 2021
7c82cd7
refactor(actions/ui): Rename ItineraryView.SPLIT>LIST
binh-dam-ibigroup Mar 30, 2021
d0a4f35
refactor(BatchResultsScreen): Add uncommited refactors from 7c82cd7
binh-dam-ibigroup Mar 30, 2021
df927a8
refactor(mobile/ResultsHeader): Reset itineraryView state when clicki…
binh-dam-ibigroup Mar 30, 2021
7678132
refactor(NarrativeItineraries): Toggle focus between leg and itinerar…
binh-dam-ibigroup Mar 31, 2021
dffebbf
refactor(NarrativeItineraries): Fix lint
binh-dam-ibigroup Mar 31, 2021
77bfc8f
refactor(mobile/results-screen): Convert options header into button+s…
binh-dam-ibigroup Mar 31, 2021
d773783
refactor(mobile/ResultsError): Convert some components to styled- per…
binh-dam-ibigroup Mar 31, 2021
48bafb6
refactor: Address PR comments.
binh-dam-ibigroup Apr 1, 2021
d634ac9
refactor(mobile/BatchResultsScreen): Style container, fix lint.
binh-dam-ibigroup Apr 1, 2021
25e497d
refactor(NarrativeItineraries): Attempt to fix lint
binh-dam-ibigroup Apr 1, 2021
1c48f41
refactor(NarrativeItineraries): Fix lint 2/
binh-dam-ibigroup Apr 1, 2021
cf678bb
refactor: Address PR comments
binh-dam-ibigroup Apr 1, 2021
3b2b880
refactor(NarrativeItineraries): Remove prop spreading.
binh-dam-ibigroup Apr 2, 2021
72fad25
Merge branch 'dev' into mobile-batch-results
binh-dam-ibigroup Apr 2, 2021
5d6a393
refactor(mobile/ResultsHeader): Reset view before clearing search.
binh-dam-ibigroup Apr 5, 2021
804b53c
refactor(mobile/EditSearchButton): Extract duplicate code.
binh-dam-ibigroup Apr 5, 2021
af9f653
fix(actions/ui): Split ItineraryView hidden state.
binh-dam-ibigroup Apr 9, 2021
403ca61
Merge branch 'dev' into mobile-batch-results
binh-dam-ibigroup Apr 9, 2021
7a8b67e
refactor(state.js): remove noisy/unneeded log statement
landonreed Apr 9, 2021
3f138bb
refactor(NarrativeItineraries): Remove unused prop.
binh-dam-ibigroup Apr 12, 2021
602e2ff
Merge branch 'mobile-batch-results' of https://github.com/opentrippla…
binh-dam-ibigroup Apr 12, 2021
43fef77
refactor(actions/ui): Extract batch results and edit search actions.
binh-dam-ibigroup Apr 13, 2021
cabab54
fix(mobile.css): Make batch settings appear under hamburger dropdown.
binh-dam-ibigroup Apr 13, 2021
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
6 changes: 6 additions & 0 deletions example.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import createLogger from 'redux-logger'

// import OTP-RR components
import {
BatchResultsScreen,
BatchRoutingPanel,
BatchSearchScreen,
CallTakerControls,
Expand All @@ -21,6 +22,7 @@ import {
DefaultItinerary,
DefaultMainPanel,
FieldTripWindows,
MobileResultsScreen,
MobileSearchScreen,
ResponsiveWebapp,
createCallTakerReducer,
Expand Down Expand Up @@ -76,6 +78,7 @@ const TermsOfStorage = () => (
// - MainControls (optional)
// - MainPanel (required)
// - MapWindows (optional)
// - MobileResultsScreen (required)
// - MobileSearchScreen (required)
// - ModeIcon (required)
// - TermsOfService (required if otpConfig.persistence.strategy === 'otp_middleware')
Expand All @@ -96,6 +99,9 @@ const components = {
<FieldTripWindows />
</>
: null,
MobileResultsScreen: isBatchRoutingEnabled
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add this component as a required component in the comment about the creation of the components variable.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in e802be6.

? BatchResultsScreen
: MobileResultsScreen,
MobileSearchScreen: isBatchRoutingEnabled
? BatchSearchScreen
: MobileSearchScreen,
Expand Down
48 changes: 46 additions & 2 deletions lib/actions/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ import coreUtils from '@opentripplanner/core-utils'
import { createAction } from 'redux-actions'
import { matchPath } from 'react-router'

import { findRoute } from './api'
import { findRoute, setUrlSearch } from './api'
import { setMapCenter, setMapZoom, setRouterId } from './config'
import { clearActiveSearch, parseUrlQueryString, setActiveSearch } from './form'
import {
clearActiveSearch,
parseUrlQueryString,
setActiveSearch
} from './form'
import { clearLocation } from './map'
import { setActiveItinerary } from './narrative'
import { getUiUrlParams } from '../util/state'
Expand Down Expand Up @@ -230,3 +234,43 @@ export const MobileScreens = {
SET_DATETIME: 7,
RESULTS_SUMMARY: 8
}

/**
* Enum to describe the layout of the itinerary view
* (currently only used in batch results).
*/
export const ItineraryView = {
DEFAULT: 'list',
/** One itinerary is shown. (In mobile view, the map is hidden.) */
FULL: 'full',
/** One itinerary is shown, itinerary and map are focused on a leg. (The mobile view is split.) */
LEG: 'leg',
/** One itinerary leg is hidden. (In mobile view, the map is expanded.) */
LEG_HIDDEN: 'leg-hidden',
/** The list of itineraries is shown. (The mobile view is split.) */
LIST: 'list',
/** The list of itineraries is hidden. (In mobile view, the map is expanded.) */
LIST_HIDDEN: 'list-hidden'
}

/**
* Sets the itinerary view state (see values above) in the URL params
* (currently only used in batch results).
*/
export function setItineraryView (value) {
return function (dispatch, getState) {
const urlParams = coreUtils.query.getUrlParams()

// If the itinerary value is changed,
// set the desired ui query param, or remove it if same as default.
if (value !== urlParams.ui_itineraryView) {
if (value !== ItineraryView.DEFAULT) {
urlParams.ui_itineraryView = value
} else if (urlParams.ui_itineraryView) {
delete urlParams.ui_itineraryView
}

dispatch(setUrlSearch(urlParams))
}
}
}
46 changes: 39 additions & 7 deletions lib/components/map/bounds-updating-overlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ function extendBoundsByPlaces (bounds, places = []) {
})
}

/** Padding around itinerary bounds and map bounds. */
const BOUNDS_PADDING = [30, 30]

/**
* This MapLayer component will automatically update the leaflet bounds
* depending on what data is in the redux store. This component does not
Expand All @@ -42,6 +45,29 @@ class BoundsUpdatingOverlay extends MapLayer {

componentWillUnmount () {}

_fitItineraryViewToMap (newProps, bounds, map) {
// If itineraryView has changed (currently: only in mobile batch results),
// force a resize of the map before re-fitting the active itinerary or active leg,
// and do that after a delay to ensure that canvas heights have stabilized in the DOM.
setTimeout(() => {
map.invalidateSize(true)

const { activeLeg, itinerary } = newProps
if (itinerary) {
if (activeLeg !== null) {
// Fit to active leg if set.
map.fitBounds(
getLeafletLegBounds(itinerary.legs[activeLeg]),
{ ITINERARY_MAP_PADDING: BOUNDS_PADDING }
)
} else {
// Fit to whole itinerary otherwise.
map.fitBounds(bounds, { ITINERARY_MAP_PADDING: BOUNDS_PADDING })
}
}
}, 250)
}

/* eslint-disable-next-line complexity */
updateBounds (oldProps, newProps) {
// TODO: maybe setting bounds ought to be handled in map props...
Expand All @@ -55,8 +81,6 @@ class BoundsUpdatingOverlay extends MapLayer {
const { map } = newProps.leaflet
if (!map) return

const padding = [30, 30]

// Fit map to to entire itinerary if active itinerary bounds changed
const newFrom = newProps.query && newProps.query.from
const newItinBounds = newProps.itinerary && getLeafletItineraryBounds(newProps.itinerary)
Expand All @@ -69,11 +93,17 @@ class BoundsUpdatingOverlay extends MapLayer {
const oldIntermediate = oldProps.query && oldProps.query.intermediatePlaces
const newIntermediate = newProps.query && newProps.query.intermediatePlaces
const intermediateChanged = !isEqual(oldIntermediate, newIntermediate)
if (

// Also refit map if itineraryView prop has changed.
const itineraryViewChanged = oldProps.itineraryView !== newProps.itineraryView

if (itineraryViewChanged) {
this._fitItineraryViewToMap(newProps, newItinBounds, map)
} else if (
(!oldItinBounds && newItinBounds) ||
(oldItinBounds && newItinBounds && !oldItinBounds.equals(newItinBounds))
) {
map.fitBounds(newItinBounds, { padding })
map.fitBounds(newItinBounds, { padding: BOUNDS_PADDING })
// Pan to to itinerary leg if made active (clicked); newly active leg must be non-null
} else if (
newProps.itinerary &&
Expand All @@ -82,7 +112,7 @@ class BoundsUpdatingOverlay extends MapLayer {
) {
map.fitBounds(
getLeafletLegBounds(newProps.itinerary.legs[newProps.activeLeg]),
{ padding }
{ padding: BOUNDS_PADDING }
)

// If no itinerary update but from/to locations are present, fit to those
Expand All @@ -108,9 +138,8 @@ class BoundsUpdatingOverlay extends MapLayer {
map.fitBounds([
[left, bottom],
[right, top]
], { padding })
], { padding: BOUNDS_PADDING })
}

// If only from or to is set, pan to that
} else if (newFrom && fromChanged) {
map.panTo([newFrom.lat, newFrom.lon])
Expand Down Expand Up @@ -141,10 +170,13 @@ class BoundsUpdatingOverlay extends MapLayer {

const mapStateToProps = (state, ownProps) => {
const activeSearch = getActiveSearch(state.otp)
const urlParams = coreUtils.query.getUrlParams()

return {
activeLeg: activeSearch && activeSearch.activeLeg,
activeStep: activeSearch && activeSearch.activeStep,
itinerary: getActiveItinerary(state.otp),
itineraryView: urlParams.ui_itineraryView,
popupLocation: state.otp.ui.mapPopupLocation,
query: state.otp.currentQuery
}
Expand Down
16 changes: 14 additions & 2 deletions lib/components/map/default-map.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import BaseMap from '@opentripplanner/base-map'
import coreUtils from '@opentripplanner/core-utils'
import React, { Component } from 'react'
import { connect } from 'react-redux'
import styled from 'styled-components'
Expand Down Expand Up @@ -119,6 +120,7 @@ class DefaultMap extends Component {
bikeRentalStations,
carRentalQuery,
carRentalStations,
itineraryView,
mapConfig,
mapPopupLocation,
vehicleRentalQuery,
Expand Down Expand Up @@ -146,16 +148,23 @@ class DefaultMap extends Component {
center={center}
maxZoom={mapConfig.maxZoom}
onClick={this.onMapClick}
popup={popup}
onPopupClosed={this.onPopupClosed}
popup={popup}
zoom={mapConfig.initZoom || 13}
>
{/* The default overlays */}
<BoundsUpdatingOverlay />
<EndpointsOverlay />
<RouteViewerOverlay />
<StopViewerOverlay />
<TransitiveOverlay />
{/*
HACK: Use the key prop to force a remount and full resizing of transitive
if the map container size changes,
per https://linguinecode.com/post/4-methods-to-re-render-react-component
Without it, transitive resolution will not match the map,
and transitive will appear blurry after e.g. the narrative is expanded.
*/}
<TransitiveOverlay key={itineraryView ? `transitive-${itineraryView}` : 'transitive-default'} />
<TripViewerOverlay />
<ElevationPointMarker />

Expand Down Expand Up @@ -206,9 +215,12 @@ const mapStateToProps = (state, ownProps) => {
const overlays = state.otp.config.map && state.otp.config.map.overlays
? state.otp.config.map.overlays
: []
const urlParams = coreUtils.query.getUrlParams()

return {
bikeRentalStations: state.otp.overlay.bikeRental.stations,
carRentalStations: state.otp.overlay.carRental.stations,
itineraryView: urlParams.ui_itineraryView,
mapConfig: state.otp.config.map,
mapPopupLocation: state.otp.ui.mapPopupLocation,
overlays,
Expand Down
Loading