-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathresults-header-and-error.js
142 lines (124 loc) · 3.88 KB
/
results-header-and-error.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import LocationIcon from '@opentripplanner/location-icon'
import PropTypes from 'prop-types'
import React, { Component } from 'react'
import { Button, Col, Row } from 'react-bootstrap'
import { connect } from 'react-redux'
import styled from 'styled-components'
import * as formActions from '../../actions/form'
import * as uiActions from '../../actions/ui'
import ErrorMessage from '../form/error-message'
import Map from '../map/map'
import {
getActiveError,
getActiveItineraries,
getActiveSearch
} from '../../util/state'
import MobileNavigationBar from './navigation-bar'
const LocationContainer = styled.div`
font-weight: 300;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
`
const LocationSummaryContainer = styled.div`
height: 50px;
left: 0;
padding-right: 10px;
position: fixed;
right: 0;
top: 50px;
`
const LocationsSummaryColFromTo = styled(Col)`
font-size: 1.1em;
line-height: 1.2em;
`
const LocationsSummaryRow = styled(Row)`
padding: 4px 8px;
`
const StyledLocationIcon = styled(LocationIcon)`
margin: 3px;
`
class ResultsHeaderAndError extends Component {
static propTypes = {
query: PropTypes.object,
resultCount: PropTypes.number,
setMobileScreen: PropTypes.func
}
_editSearchClicked = () => {
this.props.clearActiveSearch()
this.props.setMobileScreen(uiActions.MobileScreens.SEARCH_FORM)
}
render () {
const { error, query, resultCount } = this.props
const headerText = error
? 'No Trip Found'
: (resultCount
? `We Found ${resultCount} Option${resultCount > 1 ? 's' : ''}`
: 'Waiting...'
)
return (
<>
<MobileNavigationBar headerText={headerText} />
<LocationSummaryContainer>
<LocationsSummaryRow className='locations-summary'>
<LocationsSummaryColFromTo sm={11} xs={8}>
<LocationContainer>
<StyledLocationIcon type='from' /> { query.from ? query.from.name : '' }
</LocationContainer>
<LocationContainer style={{ marginTop: 2 }}>
<StyledLocationIcon type='to' /> { query.to ? query.to.name : '' }
</LocationContainer>
</LocationsSummaryColFromTo>
<Col sm={1} xs={4}>
<Button
className='edit-search-button pull-right'
onClick={this._editSearchClicked}
>Edit</Button>
</Col>
</LocationsSummaryRow>
</LocationSummaryContainer>
{error && (
<>
<div className='results-error-map'><Map /></div>
<div className='results-error-message'>
<ErrorMessage error={error} />
<div className='options-lower-tray mobile-padding'>
<Button
className='back-to-search-button'
onClick={this._editSearchClicked}
style={{ width: '100%' }}
>
<i className='fa fa-arrow-left' /> Back to Search
</Button>
</div>
</div>
</>
)}
</>
)
}
}
// connect to the redux store
const mapStateToProps = (state, ownProps) => {
const activeSearch = getActiveSearch(state.otp)
const {useRealtime} = state.otp
const response = !activeSearch
? null
: useRealtime ? activeSearch.response : activeSearch.nonRealtimeResponse
const itineraries = getActiveItineraries(state.otp)
return {
error: getActiveError(state.otp),
query: state.otp.currentQuery,
resultCount:
response
? activeSearch.query.routingType === 'ITINERARY'
? itineraries.length
: response.otp.profile.length
: null
}
}
const mapDispatchToProps = {
clearActiveSearch: formActions.clearActiveSearch,
setMobileScreen: uiActions.setMobileScreen
}
export default connect(mapStateToProps, mapDispatchToProps)(ResultsHeaderAndError)