-
Notifications
You must be signed in to change notification settings - Fork 53
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
Trip Preview #1272
Merged
Merged
Trip Preview #1272
Changes from 19 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
4c68565
feat(TripPreviewLayout): Add trip preview path+UI by duplicating prin…
binh-dam-ibigroup 36f166e
refactor(TripPreviewLayout): Display trip from tripId and redux state
binh-dam-ibigroup 9a6cd8c
feat(SavedTripList): Add link to preview trips
binh-dam-ibigroup dd64366
refactor(SavedTripList): Add trip preview i18n, combine strings
binh-dam-ibigroup 51546dc
refactor(TripPreviewLayout): Remove unneeded code
binh-dam-ibigroup 662651f
refactor(TripPreviewLayout): Update title
binh-dam-ibigroup f2057ef
refactor(SimpleMap): Introduce component, use with TripPreviewLayout.
binh-dam-ibigroup ae22791
refactor: Improve types
binh-dam-ibigroup 8d1da24
refactor(webapp-trip-preview-routes): Tweak comments
binh-dam-ibigroup af5f569
refactor(SimpleMap): Move container out of component
binh-dam-ibigroup 861323a
Merge branch 'dev' into trip-preview
binh-dam-ibigroup 650f390
refactor(TripPreviewLayoutBase): Extract common component between pri…
binh-dam-ibigroup c5b622e
refactor(SimpleMap): Add checks for null itinerary
binh-dam-ibigroup 6be5b3d
refactor(TripPreviewLayoutBase): Fix types
binh-dam-ibigroup 2db9284
refactor: Remove unused code and tweak comments
binh-dam-ibigroup 5723432
refactor(TripPreviewLayoutBase): Actually render header prop
binh-dam-ibigroup d827154
style(SimpleMap): Apply code style feedback.
binh-dam-ibigroup 6b97adf
refactor(SimpleMap): Fix types
binh-dam-ibigroup 83cadc9
refactor(SimpleMap): Remove EndpointOverlay handler after updating OT…
binh-dam-ibigroup 8a83ee5
Merge branch 'dev' into trip-preview
binh-dam-ibigroup 68d2b45
Merge branch 'dev' into trip-preview
binh-dam-ibigroup File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
import { Button } from 'react-bootstrap' | ||
import { connect } from 'react-redux' | ||
import { FormattedMessage } from 'react-intl' | ||
import { Itinerary } from '@opentripplanner/types' | ||
import { Map } from '@styled-icons/fa-solid/Map' | ||
import { Print } from '@styled-icons/fa-solid/Print' | ||
import { Times } from '@styled-icons/fa-solid/Times' | ||
// @ts-expect-error not typescripted yet | ||
import PrintableItinerary from '@opentripplanner/printable-itinerary' | ||
import React, { Component, ReactNode } from 'react' | ||
|
||
import { | ||
addPrintViewClassToRootHtml, | ||
clearClassFromRootHtml | ||
} from '../../util/print' | ||
import { AppConfig } from '../../util/config-types' | ||
import { AppReduxState } from '../../util/state-types' | ||
import { ComponentContext } from '../../util/contexts' | ||
import { IconWithText } from '../util/styledIcon' | ||
import PageTitle from '../util/page-title' | ||
import SpanWithSpace from '../util/span-with-space' | ||
import TripDetails from '../narrative/connected-trip-details' | ||
|
||
type Props = { | ||
config: AppConfig | ||
header?: ReactNode | ||
itinerary?: Itinerary | ||
mapElement?: ReactNode | ||
onClose?: () => void | ||
subTitle?: string | ||
title: string | ||
} | ||
|
||
type State = { | ||
mapVisible?: boolean | ||
} | ||
|
||
class TripPreviewLayoutBase extends Component<Props, State> { | ||
static contextType = ComponentContext | ||
|
||
constructor(props: Props) { | ||
super(props) | ||
this.state = { | ||
mapVisible: true | ||
} | ||
} | ||
|
||
_toggleMap = () => { | ||
this.setState({ mapVisible: !this.state.mapVisible }) | ||
} | ||
|
||
_print = () => { | ||
window.print() | ||
} | ||
|
||
componentDidUpdate() { | ||
// Add print-view class to html tag to ensure that iOS scroll fix only applies | ||
// to non-print views. | ||
addPrintViewClassToRootHtml() | ||
} | ||
|
||
componentWillUnmount() { | ||
clearClassFromRootHtml() | ||
} | ||
|
||
render() { | ||
const { | ||
config, | ||
header, | ||
itinerary, | ||
mapElement, | ||
onClose, | ||
subTitle = '', | ||
title | ||
} = this.props | ||
const { LegIcon } = this.context | ||
|
||
return ( | ||
<div className="otp print-layout"> | ||
<PageTitle title={[title, subTitle]} /> | ||
{/* The header bar, including the Toggle Map and Print buttons */} | ||
<div className="header"> | ||
<div style={{ float: 'right' }}> | ||
<SpanWithSpace margin={0.25}> | ||
<Button | ||
aria-expanded={this.state.mapVisible} | ||
bsSize="small" | ||
onClick={this._toggleMap} | ||
> | ||
<IconWithText Icon={Map}> | ||
<FormattedMessage id="components.PrintLayout.toggleMap" /> | ||
</IconWithText> | ||
</Button> | ||
</SpanWithSpace> | ||
<SpanWithSpace margin={0.25}> | ||
<Button bsSize="small" onClick={this._print}> | ||
<IconWithText Icon={Print}> | ||
<FormattedMessage id="common.forms.print" /> | ||
</IconWithText> | ||
</Button> | ||
</SpanWithSpace> | ||
{onClose && ( | ||
miles-grant-ibigroup marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<Button bsSize="small" onClick={onClose} role="link"> | ||
<IconWithText Icon={Times}> | ||
<FormattedMessage id="common.forms.close" /> | ||
</IconWithText> | ||
</Button> | ||
)} | ||
</div> | ||
{header} | ||
</div> | ||
|
||
{/* The map, if visible */} | ||
{this.state.mapVisible && mapElement} | ||
|
||
{/* The main itinerary body */} | ||
{itinerary && ( | ||
<> | ||
<PrintableItinerary | ||
config={config} | ||
itinerary={itinerary} | ||
LegIcon={LegIcon} | ||
/> | ||
<TripDetails className="percy-hide" itinerary={itinerary} /> | ||
</> | ||
)} | ||
</div> | ||
) | ||
} | ||
} | ||
|
||
// connect to the redux store | ||
|
||
const mapStateToProps = (state: AppReduxState) => ({ | ||
config: state.otp.config | ||
}) | ||
|
||
export default connect(mapStateToProps)(TripPreviewLayoutBase) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What was the reason behind going for a class component here rather than a function component?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copy/paste is the reason...