1
- import PrintableItinerary from '@opentripplanner/printable-itinerary'
2
- import PropTypes from 'prop-types'
3
- import React , { Component } from 'react'
4
1
import { Button } from 'react-bootstrap'
5
- import { FormattedMessage } from 'react-intl'
6
2
import { connect } from 'react-redux'
3
+ import { FormattedMessage } from 'react-intl'
4
+ import { Itinerary } from '@opentripplanner/types'
5
+ // @ts -expect-error not typescripted yet
6
+ import PrintableItinerary from '@opentripplanner/printable-itinerary'
7
+ import React , { Component } from 'react'
7
8
9
+ import {
10
+ addPrintViewClassToRootHtml ,
11
+ clearClassFromRootHtml
12
+ } from '../../util/print'
13
+ import { ComponentContext } from '../../util/contexts'
14
+ import { getActiveItinerary } from '../../util/state'
8
15
import { parseUrlQueryString } from '../../actions/form'
9
16
import { routingQuery } from '../../actions/api'
10
17
import DefaultMap from '../map/default-map'
11
- import TripDetails from '../narrative/connected-trip-details'
12
- import { ComponentContext } from '../../util/contexts'
13
18
import Icon from '../util/icon'
14
19
import SpanWithSpace from '../util/span-with-space'
15
- import { addPrintViewClassToRootHtml , clearClassFromRootHtml } from '../../util/print'
16
- import { getActiveItinerary } from '../../util/state'
20
+ import TripDetails from '../narrative/connected-trip-details'
17
21
18
- class PrintLayout extends Component {
19
- static propTypes = {
20
- itinerary : PropTypes . object ,
21
- parseUrlQueryString : PropTypes . func
22
- }
22
+ type Props = {
23
+ // TODO: Typescript config type
24
+ config : any
25
+ // TODO: typescript state.js
26
+ itinerary : any
27
+ location ?: { search ?: string }
28
+ parseUrlQueryString : ( params ?: any , source ?: string ) => any
29
+ }
30
+ type State = {
31
+ mapVisible ?: boolean
32
+ }
23
33
34
+ class PrintLayout extends Component < Props , State > {
24
35
static contextType = ComponentContext
25
36
26
- constructor ( props ) {
37
+ constructor ( props : Props ) {
27
38
super ( props )
28
39
this . state = {
29
40
mapVisible : true
@@ -38,53 +49,63 @@ class PrintLayout extends Component {
38
49
window . print ( )
39
50
}
40
51
41
- componentDidMount ( ) {
42
- const { location, parseUrlQueryString } = this . props
52
+ _close = ( ) => {
53
+ window . location . replace ( String ( window . location ) . replace ( 'print/' , '' ) )
54
+ }
55
+
56
+ componentDidMount ( ) {
57
+ const { itinerary, location, parseUrlQueryString } = this . props
43
58
// Add print-view class to html tag to ensure that iOS scroll fix only applies
44
59
// to non-print views.
45
60
addPrintViewClassToRootHtml ( )
46
61
// Parse the URL query parameters, if present
47
- if ( location && location . search ) {
62
+ if ( ! itinerary && location && location . search ) {
48
63
parseUrlQueryString ( )
49
64
}
50
65
}
51
66
52
- componentWillUnmount ( ) {
67
+ componentWillUnmount ( ) {
53
68
clearClassFromRootHtml ( )
54
69
}
55
70
56
- render ( ) {
71
+ render ( ) {
57
72
const { config, itinerary } = this . props
58
73
const { LegIcon } = this . context
59
74
60
75
return (
61
- < div className = ' otp print-layout' >
76
+ < div className = " otp print-layout" >
62
77
{ /* The header bar, including the Toggle Map and Print buttons */ }
63
- < div className = ' header' >
78
+ < div className = " header" >
64
79
< div style = { { float : 'right' } } >
65
80
< SpanWithSpace margin = { 0.25 } >
66
- < Button bsSize = 'small' onClick = { this . _toggleMap } >
67
- < Icon type = 'map' withSpace />
68
- < FormattedMessage id = 'components.PrintLayout.toggleMap' />
81
+ < Button bsSize = "small" onClick = { this . _toggleMap } >
82
+ < Icon type = "map" withSpace />
83
+ < FormattedMessage id = "components.PrintLayout.toggleMap" />
84
+ </ Button >
85
+ </ SpanWithSpace >
86
+ < SpanWithSpace margin = { 0.25 } >
87
+ < Button bsSize = "small" onClick = { this . _print } >
88
+ < Icon type = "print" withSpace />
89
+ < FormattedMessage id = "common.forms.print" />
69
90
</ Button >
70
91
</ SpanWithSpace >
71
- < Button bsSize = ' small' onClick = { this . _print } >
72
- < Icon type = 'print' withSpace />
73
- < FormattedMessage id = ' common.forms.print' />
92
+ < Button bsSize = " small" onClick = { this . _close } >
93
+ < Icon type = "close" withSpace />
94
+ < FormattedMessage id = " common.forms.close" />
74
95
</ Button >
75
96
</ div >
76
- < FormattedMessage id = ' components.PrintLayout.itinerary' />
97
+ < FormattedMessage id = " components.PrintLayout.itinerary" />
77
98
</ div >
78
99
79
100
{ /* The map, if visible */ }
80
- { this . state . mapVisible &&
81
- < div className = ' map-container' >
101
+ { this . state . mapVisible && (
102
+ < div className = " map-container" >
82
103
< DefaultMap />
83
104
</ div >
84
- }
105
+ ) }
85
106
86
107
{ /* The main itinerary body */ }
87
- { itinerary &&
108
+ { itinerary && (
88
109
< >
89
110
< PrintableItinerary
90
111
config = { config }
@@ -93,15 +114,16 @@ class PrintLayout extends Component {
93
114
/>
94
115
< TripDetails itinerary = { itinerary } />
95
116
</ >
96
- }
117
+ ) }
97
118
</ div >
98
119
)
99
120
}
100
121
}
101
122
102
123
// connect to the redux store
103
124
104
- const mapStateToProps = ( state , ownProps ) => {
125
+ // TODO: Typescript state
126
+ const mapStateToProps = ( state : any ) => {
105
127
return {
106
128
config : state . otp . config ,
107
129
itinerary : getActiveItinerary ( state )
0 commit comments