Skip to content

Commit

Permalink
refactor(css): Include CSS where it's being used directly.
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorgerhardt committed Feb 28, 2019
1 parent 2a390b1 commit 5b2f6b7
Show file tree
Hide file tree
Showing 12 changed files with 135 additions and 137 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@
"next": "v8.0.3",
"next-cookies": "^1.1.2",
"node-fetch": "^2.3.0",
"normalize.css": "^8.0.1",
"react": "v16.8.3",
"react-dom": "v16.8.3",
"react-modal": "^3.8.1",
"react-redux": "^6.0.1",
"react-select": "^1.2.1",
"react-select-fast-filter-options": "^0.2.3",
Expand Down
1 change: 1 addition & 0 deletions pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import message from '../src/message'
import * as select from '../src/selectors'
import configureTaui from '../src/services/config'

import 'normalize.css'
import '../src/style.css'

// Set the title
Expand Down
7 changes: 1 addition & 6 deletions src/components/application.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @flow
import lonlat from '@conveyal/lonlat'
import Icon from '@conveyal/woonerf/components/icon'
import get from 'lodash/get'
Expand Down Expand Up @@ -65,10 +64,6 @@ export default class Application extends Component {
}
}

_onTimeCutoffChange = (event) => {
this.props.setTimeCutoff(parseInt(event.currentTarget.value, 10))
}

_downloadIsochrone = memoize(index => () => {
const p = this.props
const isochrone = p.isochrones[index]
Expand Down Expand Up @@ -114,7 +109,7 @@ export default class Application extends Component {
<Form
end={p.end}
geocode={p.geocode}
onTimeCutoffChange={this._onTimeCutoffChange}
onTimeCutoffChange={p.setTimeCutoff}
onChangeEnd={this._setEndWithFeature}
onChangeStart={this._setStartWithFeature}
pointsOfInterest={p.pointsOfInterestOptions}
Expand Down
2 changes: 1 addition & 1 deletion src/components/dock.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default function Dock (props) {
return <div className='Taui-Dock'>
<div className='Taui-Dock-content'>
<div className='title'>
<Icon type='map' />}
<Icon type='map' />
{' '}
{props.title || message('Title')}
</div>
Expand Down
132 changes: 39 additions & 93 deletions src/components/form.js
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}
/>
</>}
</>
}
2 changes: 2 additions & 0 deletions src/components/geocoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import Select from 'react-select'

import message from '../message'

import 'react-select/dist/react-select.css'

const USE_GEOLOCATE = true
const GEOLOCATE_VALUE = 'geolocate'
const RATE_LIMIT = 500
Expand Down
2 changes: 2 additions & 0 deletions src/components/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import useMap from '../hooks/use-map'
import useMarker from '../hooks/use-marker'
import usePointsOfInterest from '../hooks/use-points-of-interest'

import 'mapbox-gl/dist/mapbox-gl.css'

const containerStyle = {height: '100%', width: '100%'}

// Always use the same markers
Expand Down
16 changes: 16 additions & 0 deletions src/components/poi-select.js
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)}
/>
}
46 changes: 46 additions & 0 deletions src/components/time-cutoff.js
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>
</>
}
5 changes: 4 additions & 1 deletion src/selectors/points-of-interest-options.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import lonlat from '@conveyal/lonlat'
import {createSelector} from 'reselect'

export default createSelector(
Expand All @@ -7,10 +8,12 @@ export default createSelector(
? featureCollection.features.map(feature => {
const p = feature.properties
const label = p.label || p.name || p.Name
const coordinates = feature.geometry.coordinates
return {
label,
position: lonlat(coordinates),
value: `poi-${label}-${feature.geometry.coordinates.join(',')}`,
coordinates: feature.geometry.coordinates
coordinates
}
})
: []
Expand Down
35 changes: 0 additions & 35 deletions src/style.css
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
@import url('https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.0/normalize.min.css');
@import url('https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css');
@import url(../node_modules/mapbox-gl/dist/mapbox-gl.css);
@import url(../node_modules/react-select/dist/react-select.css);
@import url(../node_modules/react-virtualized/styles.css);
@import url(../node_modules/react-virtualized-select/styles.css);
@import url(components/log/style.css);

/** Colors from https://palx.jxnblk.com/2389c9 **/
Expand Down Expand Up @@ -298,40 +293,10 @@ table.CardContent td:first-of-type {
display: inline-block;
}

.map-legends,
.map-tooltip {
border-radius: var(--rad);
background-color: var(--dark-blue);
font-size: 1rem;
color: #fff;
}

.mapboxgl-popup {
font-size: 1.1rem;
}

.Popup button {
display: block;
font-size: 1rem;
padding: 0.5rem 1rem;
border-radius: var(--rad);
margin-bottom: 0.5rem;
cursor: pointer;
color: var(--dark-blue);
background-color: rgba(255, 255, 255, 0.95);
border: none;
width: 100%;
text-align: left;
}

.Popup button:last-of-type {
margin-bottom: 0;
}

.Popup button:hover {
background-color: #fff;
}

.Fullscreen {
position: absolute;
height: 100%;
Expand Down
Loading

0 comments on commit 5b2f6b7

Please sign in to comment.