-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathbatch-results-screen.js
123 lines (107 loc) · 3.17 KB
/
batch-results-screen.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
import PropTypes from 'prop-types'
import React, { Component } from 'react'
import { Button } from 'react-bootstrap'
import { connect } from 'react-redux'
import styled from 'styled-components'
import Map from '../map/map'
import Icon from '../narrative/icon'
import NarrativeItineraries from '../narrative/narrative-itineraries'
import { getActiveError } from '../../util/state'
import MobileContainer from './container'
import ResultsHeaderAndError from './results-header-and-error'
const StyledMobileContainer = styled(MobileContainer)`
.options > .header {
margin: 10px;
}
&.otp.mobile .mobile-narrative-container {
bottom: 0;
left: 0;
overflow-y: auto;
padding: 0;
position: fixed;
right: 0;
}
`
const ExpandMapButton = styled(Button)`
bottom: 25px;
position: absolute;
right: 10px;
z-index: 999999;
`
class BatchMobileResultsScreen extends Component {
static propTypes = {
error: PropTypes.object
}
constructor () {
super()
this.state = {
itineraryExpanded: false,
mapExpanded: false
}
}
componentDidUpdate (prevProps) {
// Check if the active leg changed
if (this.props.activeLeg !== prevProps.activeLeg) {
this._setItineraryExpanded(false)
}
}
_setItineraryExpanded = itineraryExpanded => {
this.setState({ itineraryExpanded })
}
_toggleMapExpanded = () => {
this.setState({ mapExpanded: !this.state.mapExpanded })
}
renderMap () {
const { mapExpanded } = this.state
return (
<div className='results-map' style={{bottom: mapExpanded ? 0 : '60%'}}>
<Map />
<ExpandMapButton
bsSize='small'
onClick={this._toggleMapExpanded}
>
<Icon name={mapExpanded ? 'list-ul' : 'arrows-alt'} />
{mapExpanded ? 'Show results' : 'Expand map'}
</ExpandMapButton>
</div>
)
}
render () {
const { error } = this.props
const { itineraryExpanded, mapExpanded } = this.state
return (
<StyledMobileContainer>
<ResultsHeaderAndError />
{!error && (mapExpanded
// Set up two separate renderings of the map according to mapExpanded,
// so that the map is properly sized and itineraries fit under either conditions.
// (Otherwise, if just the narrative is added/removed, the map doesn't resize properly.)
? this.renderMap()
: (
<>
{!itineraryExpanded && this.renderMap()}
<div className='mobile-narrative-container' style={{top: itineraryExpanded ? '100px' : '40%'}}>
<NarrativeItineraries
containerStyle={{
display: 'flex',
flexDirection: 'column',
height: '100%',
width: '100%'
}}
onToggleDetailedItinerary={this._setItineraryExpanded}
/>
</div>
</>
))
}
</StyledMobileContainer>
)
}
}
// connect to the redux store
const mapStateToProps = (state, ownProps) => {
return {
error: getActiveError(state.otp)
}
}
export default connect(mapStateToProps)(BatchMobileResultsScreen)