-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(css): Include CSS where it's being used directly.
- Loading branch information
1 parent
2a390b1
commit 5b2f6b7
Showing
12 changed files
with
135 additions
and
137 deletions.
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 |
---|---|---|
@@ -1,107 +1,53 @@ | ||
import lonlat from '@conveyal/lonlat' | ||
import Icon from '@conveyal/woonerf/components/icon' | ||
import memoize from 'lodash/memoize' | ||
import dynamic from 'next/dynamic' | ||
import React from 'react' | ||
import Select from 'react-virtualized-select' | ||
import createFilterOptions from 'react-select-fast-filter-options' | ||
|
||
import message from '../message' | ||
|
||
import Geocoder from './geocoder' | ||
|
||
const cfo = memoize(o => createFilterOptions({options: o})) | ||
|
||
export default class Form extends React.PureComponent { | ||
state = { | ||
animating: false | ||
} | ||
|
||
_animateTimeCutoff = () => { | ||
this.setState({animating: true}) | ||
this._animateTo(0) | ||
} | ||
|
||
_animateTo (cutoff) { | ||
this.props.onTimeCutoffChange({currentTarget: {value: cutoff}}) | ||
if (cutoff < 120) setTimeout(() => this._animateTo(cutoff + 1), 50) | ||
else this.setState({animating: false}) | ||
} | ||
|
||
_selectPoiStart = (option) => | ||
this.props.updateStart(option ? { | ||
label: option.label, | ||
position: lonlat(option.coordinates) | ||
} : null) | ||
|
||
_selectPoiEnd = (option) => | ||
this.props.updateEnd(option ? { | ||
label: option.label, | ||
position: lonlat(option.coordinates) | ||
} : null) | ||
|
||
render () { | ||
const p = this.props | ||
const poi = p.pointsOfInterest || [] | ||
const filterPoi = cfo(poi) // memoized filtering function | ||
return ( | ||
<React.Fragment> | ||
import TimeCutoff from './time-cutoff' | ||
|
||
// Not always used | ||
const PoiSelect = dynamic(() => import('./poi-select')) | ||
|
||
export default function Form (p) { | ||
const poi = p.pointsOfInterest || [] | ||
return <> | ||
{p.searchPoiOnly | ||
? <PoiSelect | ||
clearable={false} | ||
options={poi} | ||
onChange={p.updateStart} | ||
placeholder={message('Geocoding.StartPlaceholder')} | ||
value={p.start} | ||
/> | ||
: <Geocoder | ||
clearable={false} | ||
geocode={p.geocode} | ||
onChange={p.onChangeStart} | ||
placeholder={message('Geocoding.StartPlaceholder')} | ||
reverseGeocode={p.reverseGeocode} | ||
value={p.start} | ||
/>} | ||
{p.start && | ||
<> | ||
{p.searchPoiOnly | ||
? <Select | ||
clearable={false} | ||
filterOptions={filterPoi} | ||
? <PoiSelect | ||
options={poi} | ||
onChange={this._selectPoiStart} | ||
placeholder={message('Geocoding.StartPlaceholder')} | ||
value={p.start} | ||
onChange={p.updateEnd} | ||
placeholder={message('Geocoding.EndPlaceholder')} | ||
value={p.end} | ||
/> | ||
: <Geocoder | ||
clearable={false} | ||
geocode={p.geocode} | ||
onChange={p.onChangeStart} | ||
onChange={p.onChangeEnd} | ||
placeholder={message('Geocoding.StartPlaceholder')} | ||
reverseGeocode={p.reverseGeocode} | ||
value={p.start} | ||
value={p.end} | ||
/>} | ||
{p.start && | ||
<React.Fragment> | ||
{p.searchPoiOnly | ||
? <Select | ||
filterOptions={filterPoi} | ||
options={poi} | ||
onChange={this._selectPoiEnd} | ||
placeholder={message('Geocoding.EndPlaceholder')} | ||
value={p.end} | ||
/> | ||
: <Geocoder | ||
geocode={p.geocode} | ||
onChange={p.onChangeEnd} | ||
placeholder={message('Geocoding.StartPlaceholder')} | ||
reverseGeocode={p.reverseGeocode} | ||
value={p.end} | ||
/>} | ||
<div className='heading'> | ||
{message('Strings.HighlightAreaAccessibleWithin')} | ||
{this.state.animating || | ||
<a className='pull-right' onClick={this._animateTimeCutoff}> | ||
<Icon type='play' /> | ||
</a>} | ||
</div> | ||
<div className='TimeCutoff'> | ||
<div className='Time'> | ||
{p.selectedTimeCutoff} {message('Units.Minutes')} | ||
</div> | ||
<input | ||
disabled={this.state.animating} | ||
onChange={p.onTimeCutoffChange} | ||
type='range' | ||
min={10} | ||
max={120} | ||
step={1} | ||
value={p.selectedTimeCutoff} | ||
/> | ||
</div> | ||
</React.Fragment>} | ||
</React.Fragment> | ||
) | ||
} | ||
<TimeCutoff | ||
cutoff={p.selectedTimeCutoff} | ||
setCutoff={p.onTimeCutoffChange} | ||
/> | ||
</>} | ||
</> | ||
} |
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,16 @@ | ||
import memoize from 'lodash/memoize' | ||
import React from 'react' | ||
import Select from 'react-virtualized-select' | ||
import createFilterOptions from 'react-select-fast-filter-options' | ||
|
||
import 'react-virtualized/styles.css' | ||
import 'react-virtualized-select/styles.css' | ||
|
||
const cfo = memoize(o => createFilterOptions({options: o})) | ||
|
||
export default function PoiSelect(p) { | ||
return <Select | ||
{...p} // clearable, onChange, options, placeholder, value | ||
filterOptions={cfo(p.options)} | ||
/> | ||
} |
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,46 @@ | ||
import Icon from '@conveyal/woonerf/components/icon' | ||
import React from 'react' | ||
|
||
import message from '../message' | ||
|
||
// Delay in animating the time cutoff | ||
const DELAY = 50 | ||
|
||
export default function TimeCutoff (p) { | ||
const [animating, setAnimating] = React.useState(false) | ||
|
||
React.useEffect(() => { | ||
if (!animating) return | ||
if (p.cutoff < 120) { | ||
setTimeout(() => p.setCutoff(p.cutoff + 1), 50) | ||
} else { | ||
setAnimating(false) | ||
} | ||
}, [animating, p.cutoff]) | ||
|
||
return <> | ||
<div className='heading'> | ||
{message('Strings.HighlightAreaAccessibleWithin')} | ||
{animating || | ||
<a className='pull-right' onClick={() => { | ||
setAnimating(true) | ||
p.setCutoff(10) | ||
}}> | ||
<Icon type='play' /> | ||
</a>} | ||
</div> | ||
<div className='TimeCutoff'> | ||
<div className='Time'>{p.cutoff} {message('Units.Minutes')}</div> | ||
<input | ||
disabled={animating} | ||
onChange={e => | ||
p.setCutoff(parseInt(e.currentTarget.value, 10))} | ||
type='range' | ||
min={10} | ||
max={120} | ||
step={1} | ||
value={p.cutoff} | ||
/> | ||
</div> | ||
</> | ||
} |
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
Oops, something went wrong.