Skip to content
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

Advanced Trip Form Panel #1230

Merged
merged 30 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
12692f9
Create advanced settings panel
amy-corson-ibigroup Jun 10, 2024
3374486
Merge branch 'dev' into advanced-trip-form-panel
amy-corson-ibigroup Jun 10, 2024
6bfcf27
refactor(advanced-settings-panel): clean up css, add focus trap, add …
amy-corson-ibigroup Jun 10, 2024
9a5f4af
Fix animation timing
amy-corson-ibigroup Jun 10, 2024
88b3038
Close advanced panel on page change
amy-corson-ibigroup Jun 10, 2024
e5c0192
create PANEL_ANIMATION_TIMING variable
amy-corson-ibigroup Jun 10, 2024
c80a8ba
Smooth animation
amy-corson-ibigroup Jun 10, 2024
8fbabd2
revert example.css changes
amy-corson-ibigroup Jun 10, 2024
5f4268c
Add AdvancedModePanel to mobile search
amy-corson-ibigroup Jun 10, 2024
f2462aa
fix(batch-routing-panel): Remove itins and user settings if advanced …
amy-corson-ibigroup Jun 10, 2024
ab198f1
Clean up animation + add prefersReducedMotion util
amy-corson-ibigroup Jun 10, 2024
3690005
Clean up comments, tweak css
amy-corson-ibigroup Jun 10, 2024
31520af
Sort css
amy-corson-ibigroup Jun 10, 2024
a6ca364
update animation from homepage to advanced settings
amy-corson-ibigroup Jun 11, 2024
75f8a7f
messy first pass of bringing in advanced settings from otp ui
daniel-heppner-ibigroup Jun 14, 2024
fc07097
add react-transition-group to advanced panel
amy-corson-ibigroup Jun 14, 2024
e7f34c4
Merge branch 'advanced-trip-form-panel' of https://github.com/opentri…
amy-corson-ibigroup Jun 14, 2024
9af5feb
Fix innerRef
amy-corson-ibigroup Jun 14, 2024
55a26dc
cleanup and address PR feedback
amy-corson-ibigroup Jun 14, 2024
5eef8ff
Add react-transition-group for mobile screens
amy-corson-ibigroup Jun 14, 2024
96e4bc8
fix bad merge
amy-corson-ibigroup Jun 14, 2024
5eb6f41
upgrade trip-form downgrade animate height
daniel-heppner-ibigroup Jun 15, 2024
5551187
finish wiring up advanced settings pane
daniel-heppner-ibigroup Jun 15, 2024
58e1258
tweak styling and remove focustrapwrapper
amy-corson-ibigroup Jun 17, 2024
e4ee080
Update accentColor for AdvancedModeSubsettingsContainer and update al…
amy-corson-ibigroup Jun 18, 2024
ac1020e
Turn h2 into subheader component
amy-corson-ibigroup Jun 18, 2024
35b0062
fix passing accent color to AdvancedModeSubsettingsContainer
amy-corson-ibigroup Jun 19, 2024
623b5ca
remove unnecessary classname from subheader
amy-corson-ibigroup Jun 19, 2024
cb142d0
update otp-ui and animation durations
amy-corson-ibigroup Jun 21, 2024
c7d2b92
remove unecessary closepanel function
amy-corson-ibigroup Jun 21, 2024
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
2 changes: 1 addition & 1 deletion example.css
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@
height: 100%;
margin: 0px;
padding: 0px;
}
}
5 changes: 5 additions & 0 deletions i18n/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,13 @@ components:
BatchRoutingPanel:
shortTitle: Plan Trip
BatchSearchScreen:
advancedHeader: Advanced Preferences
closeAdvancedPreferences: Close advanced preferences
header: Plan Your Trip
modeOptions: Mode Options
modeSelectorLabel: Select a travel mode
moreOptions: More options
tripOptions: Trip Options
BatchSettings:
destination: destination
invalidModeSelection: >-
Expand Down
193 changes: 144 additions & 49 deletions lib/components/app/batch-routing-panel.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
import { connect } from 'react-redux'
import { CSSTransition, TransitionGroup } from 'react-transition-group'
import { FormattedMessage, injectIntl, IntlShape } from 'react-intl'
import React, { Component, FormEvent } from 'react'

import { getActiveSearch, getShowUserSettings } from '../../util/state'
import { getPersistenceMode } from '../../util/user'
import AdvancedSettingsPanel from '../form/advanced-settings-panel'
import BatchSettings from '../form/batch-settings'
import InvisibleA11yLabel from '../util/invisible-a11y-label'
import LocationField from '../form/connected-location-field'
import NarrativeItineraries from '../narrative/narrative-itineraries'
import React, { Component, FormEvent } from 'react'

import {
advancedPanelClassName,
mainPanelClassName,
transitionDuration,
TransitionStyles
} from '../form/styled'
import SwitchButton from '../form/switch-button'
import UserSettings from '../form/user-settings'
import ViewerContainer from '../viewers/viewer-container'

interface Props {
activeSearch: any
intl: IntlShape
mainPanelContent: number
mobile?: boolean
showUserSettings: boolean
}
Expand All @@ -24,7 +34,26 @@ interface Props {
*/
class BatchRoutingPanel extends Component<Props> {
state = {
planTripClicked: false
planTripClicked: false,
reverse: false,
showAdvancedModeSettings: false
}

_advancedSettingRef = React.createRef<HTMLDivElement>()
_mainPanelContentRef = React.createRef<HTMLDivElement>()
_itinerariesAndUserRef = React.createRef<HTMLDivElement>()

componentDidUpdate(prevProps: Readonly<Props>): void {
// Close the advanced mode settings if we navigate to another page
if (
prevProps.mainPanelContent === null &&
this.props.mainPanelContent !== null &&
this.state.showAdvancedModeSettings
) {
this.setState({
showAdvancedModeSettings: false
})
}
}

handleSubmit = (e: FormEvent) => e.preventDefault()
Expand All @@ -33,6 +62,14 @@ class BatchRoutingPanel extends Component<Props> {
this.setState({ planTripClicked: true })
}

handleOpenAdvanceSettings = () => {
this.setState({ showAdvancedModeSettings: true })
}

handleCloseAdvanceSettings = () => {
this.setState({ showAdvancedModeSettings: false })
}

render() {
const { activeSearch, intl, mobile, showUserSettings } = this.props
const { planTripClicked } = this.state
Expand All @@ -53,55 +90,110 @@ class BatchRoutingPanel extends Component<Props> {
height: '100%'
}}
>
<InvisibleA11yLabel>
<h1>
<FormattedMessage id="components.BatchSearchScreen.header" />
</h1>
</InvisibleA11yLabel>
<form
className="form"
onSubmit={this.handleSubmit}
style={{ padding: '10px' }}
>
<span className="batch-routing-panel-location-fields">
<LocationField
inputPlaceholder={intl.formatMessage(
{ id: 'common.searchForms.enterStartLocation' },
{ mapAction }
<TransitionStyles>
{!this.state.showAdvancedModeSettings && (
<InvisibleA11yLabel>
<h1>
<FormattedMessage id="components.BatchSearchScreen.header" />
</h1>
</InvisibleA11yLabel>
)}
<form
className="form"
onSubmit={this.handleSubmit}
style={{ padding: '10px' }}
>
<TransitionGroup style={{ display: 'content' }}>
{this.state.showAdvancedModeSettings && (
<CSSTransition
classNames={advancedPanelClassName}
nodeRef={this._advancedSettingRef}
timeout={transitionDuration}
>
<AdvancedSettingsPanel
closeAdvancedSettings={this.handleCloseAdvanceSettings}
innerRef={this._advancedSettingRef}
/>
</CSSTransition>
)}
isRequired
locationType="from"
selfValidate={planTripClicked}
showClearButton={!mobile}
/>
<LocationField
inputPlaceholder={intl.formatMessage(
{ id: 'common.searchForms.enterDestination' },
{ mapAction }

{!this.state.showAdvancedModeSettings && (
<CSSTransition
classNames={mainPanelClassName}
nodeRef={this._mainPanelContentRef}
onExit={
() => this.setState({ showAdvancedModeSettings: true })
// eslint-disable-next-line react/jsx-curly-newline
}
timeout={transitionDuration}
>
<div ref={this._mainPanelContentRef}>
<span className="batch-routing-panel-location-fields">
<LocationField
inputPlaceholder={intl.formatMessage(
{ id: 'common.searchForms.enterStartLocation' },
{ mapAction }
)}
isRequired
locationType="from"
selfValidate={planTripClicked}
showClearButton={!mobile}
/>
<LocationField
inputPlaceholder={intl.formatMessage(
{ id: 'common.searchForms.enterDestination' },
{ mapAction }
)}
isRequired
locationType="to"
selfValidate={planTripClicked}
showClearButton={!mobile}
/>
<div className="switch-button-container">
<SwitchButton />
</div>
</span>
<BatchSettings
onPlanTripClick={this.handlePlanTripClick}
openAdvancedSettings={this.handleOpenAdvanceSettings}
/>
</div>
</CSSTransition>
)}
isRequired
locationType="to"
selfValidate={planTripClicked}
showClearButton={!mobile}
/>
<div className="switch-button-container">
<SwitchButton />
</div>
</span>
<BatchSettings onPlanTripClick={this.handlePlanTripClick} />
</form>
{!activeSearch && showUserSettings && (
<UserSettings style={{ margin: '0 10px', overflowY: 'auto' }} />
)}
<div
className="desktop-narrative-container"
style={{
flexGrow: 1,
overflowY: 'hidden'
}}
>
<NarrativeItineraries />
</div>
</TransitionGroup>
</form>
<TransitionGroup style={{ height: '100%' }}>
{!this.state.showAdvancedModeSettings && (
<CSSTransition
classNames={mainPanelClassName}
nodeRef={this._itinerariesAndUserRef}
timeout={transitionDuration}
>
<div
ref={this._itinerariesAndUserRef}
style={{ height: '100%' }}
>
{!activeSearch && showUserSettings && (
<UserSettings
style={{ margin: '0 10px', overflowY: 'auto' }}
/>
)}

<div
className="desktop-narrative-container"
style={{
flexGrow: 1,
height: '100%',
overflowY: 'hidden'
}}
>
<NarrativeItineraries />
</div>
</div>
</CSSTransition>
)}
</TransitionGroup>
</TransitionStyles>
</ViewerContainer>
)
}
Expand All @@ -115,8 +207,11 @@ const mapStateToProps = (state: any) => {
getShowUserSettings(state) &&
(state.user.loggedInUser?.hasConsentedToTerms ||
getPersistenceMode(state.otp.config.persistence).isLocalStorage)
const { mainPanelContent } = state.otp.ui

return {
activeSearch: getActiveSearch(state),
mainPanelContent,
showUserSettings
}
}
Expand Down
31 changes: 31 additions & 0 deletions lib/components/form/advanced-settings-button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { ArrowRight } from '@styled-icons/fa-solid'
import { FormattedMessage } from 'react-intl'

import { grey } from '../util/colors'
import React from 'react'
import styled from 'styled-components'

interface Props {
onClick: () => void
}

const StyledTransparentButton = styled.button`
align-items: center;
background: transparent;
border: none;
color: ${grey[800]};
display: flex;
gap: 7px;
margin-bottom: 5px;
`

const AdvancedSettingsButton = ({ onClick }: Props): JSX.Element => {
return (
<StyledTransparentButton onClick={onClick}>
<FormattedMessage id="components.BatchSearchScreen.moreOptions" />
<ArrowRight size={18} />
</StyledTransparentButton>
)
}

export default AdvancedSettingsButton
Loading
Loading