-
Notifications
You must be signed in to change notification settings - Fork 11
Get location #148
Get location #148
Changes from 3 commits
58a2c20
f9e6de1
f8a167c
5c3f585
0b164cb
71d7cd8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
'use strict'; | ||
|
||
const Controller = require('trails-controller'); | ||
const fetch = require('isomorphic-fetch'); | ||
const GOOGLE_API_KEY = process.env.GOOGLE_API_KEY; | ||
const geocodingUrl = 'https://maps.googleapis.com/maps/api/geocode/json'; | ||
|
||
/** | ||
* @module GeolocationController | ||
* @description A controller for handling Geolocation requests. | ||
*/ | ||
module.exports = class GeolocationController extends Controller { | ||
|
||
get(request, reply) { | ||
const address = JSON.stringify(request.query.address); | ||
|
||
fetch(`${geocodingUrl}?address=${address}&key=${GOOGLE_API_KEY}`) | ||
.then((response) => response.json()) | ||
.then((response) => { | ||
reply(response); | ||
}) | ||
.catch((error) => { | ||
reply(error); | ||
}); | ||
} | ||
|
||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
'use strict'; | ||
|
||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
class Hr extends Component { | ||
render() { | ||
return ( | ||
<div className="hr"> | ||
<div className="hr-line"></div> | ||
{ | ||
this.props.label && | ||
<label className="hr-label">{this.props.label}</label> | ||
} | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
Hr.propTypes = { | ||
label: PropTypes.string, | ||
color: PropTypes.string | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. color is not used at all in this component There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The goal was that the developer could change the color of the HR where needed. I'll update the PR. |
||
}; | ||
|
||
export default Hr; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
'use strict'; | ||
|
||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import Hr from './../atoms/hr'; | ||
import Alert from './../organisms/Alert'; | ||
import TextField from './../organisms/TextField'; | ||
|
||
import { | ||
getLocationByGPS, | ||
getLocationByAddress | ||
} from './../../redux/actions/pick-survey-actions'; | ||
|
||
class LocationForm extends Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = {address: ''}; | ||
} | ||
|
||
updateAddress(event) { | ||
const address = event.target.value; | ||
this.setState({ | ||
address: address | ||
}); | ||
} | ||
|
||
search(event) { | ||
event && event.preventDefault(); | ||
this.props.dispatch(getLocationByAddress(this.state.address), () => { | ||
this.setState({address: ''}); | ||
}); | ||
} | ||
|
||
geolocate() { | ||
this.props.dispatch(getLocationByGPS()); | ||
} | ||
|
||
render() { | ||
return ( | ||
<form className="location-form" onSubmit={this.search.bind(this)}> | ||
<section> | ||
{this.props.status.message && | ||
<Alert | ||
level={this.props.status.level} | ||
message={this.props.status.message} /> | ||
} | ||
</section> | ||
<section className="by-address"> | ||
<TextField | ||
label="Locate Using Address" | ||
name="address" | ||
value={this.state.value} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this implicitly the state or are we setting an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This works (because JavaScript), but it we should be setting |
||
onChange={this.updateAddress.bind(this)} | ||
button={ | ||
<button | ||
type="button" | ||
onClick={this.search.bind(this)}> | ||
Search | ||
</button> | ||
}/> | ||
</section> | ||
<Hr label="or" /> | ||
<section className="by-gps"> | ||
<label htmlFor="gps">Or use GPS</label> | ||
<button | ||
type="button" | ||
id="gps" | ||
onClick={this.geolocate.bind(this)}> | ||
Use GPS | ||
</button> | ||
</section> | ||
</form> | ||
); | ||
} | ||
} | ||
|
||
LocationForm.propTypes = { | ||
dispatch: PropTypes.func, | ||
addressError: PropTypes.string, | ||
status: PropTypes.object | ||
}; | ||
|
||
export default LocationForm; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
import React, { PropTypes, Component } from 'react'; | ||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import { connect } from 'react-redux'; | ||
|
||
import Card from './../atoms/Card'; | ||
import LocationForm from './../ecosystems/LocationForm'; | ||
|
||
class Home extends Component { | ||
|
||
|
@@ -15,6 +18,10 @@ class Home extends Component { | |
<div className="twelve columns"> | ||
<Card> | ||
<pre>OKCandidate Home Screen</pre> | ||
<LocationForm | ||
addressError={this.props.pickSurvey.addressError} | ||
status={this.props.pickSurvey.status} | ||
dispatch={this.props.dispatch} /> | ||
</Card> | ||
</div> | ||
); | ||
|
@@ -24,12 +31,14 @@ class Home extends Component { | |
} | ||
|
||
Home.propTypes = { | ||
user: PropTypes.object | ||
user: PropTypes.object, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how is user passed into this component? unclear after looking at top level routes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be coming from the global store through |
||
pickSurvey: PropTypes.object, | ||
dispatch: PropTypes.func | ||
}; | ||
|
||
export default connect( | ||
state => ({ | ||
survey: state.survey, | ||
pickSurvey: state.pickSurvey, | ||
ui: state.ui | ||
}) | ||
)(Home); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
'use strict'; | ||
|
||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import { connect } from 'react-redux'; | ||
|
||
import Card from './../atoms/Card'; | ||
|
||
class SurveySelector extends Component { | ||
constructor(props) { | ||
super(props); | ||
} | ||
|
||
render() { | ||
return ( | ||
<section> | ||
<Card> | ||
<pre>Survey Selector</pre> | ||
</Card> | ||
</section> | ||
); | ||
} | ||
} | ||
|
||
SurveySelector.propTypes = { | ||
surveys: PropTypes.array | ||
}; | ||
|
||
export default connect( | ||
state => ({ | ||
pickSurvey: state.pickSurvey, | ||
ui: state.ui | ||
}) | ||
)(SurveySelector); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
'use strict'; | ||
|
||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
class TextField extends Component { | ||
render() { | ||
return ( | ||
<div className="text-field"> | ||
{ | ||
this.props.label && | ||
<label htmlFor={this.props.name}> | ||
{this.props.label} | ||
</label> | ||
} | ||
<div className={`text-field-input ${this.props.button && 'has-button'}`}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we've declared this.props.button as an element type but using it in this context as a string, what happens? would be serializing the elm? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is checking to see if |
||
<input | ||
id={this.props.name} | ||
type={this.props.type || 'text'} | ||
value={this.props.value} | ||
onChange={this.props.onChange} /> | ||
{ this.props.button } | ||
</div> | ||
{ | ||
this.props.error && | ||
<div className="text-field-error"> | ||
<span>{this.props.error}</span> | ||
</div> | ||
} | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
TextField.propTypes = { | ||
name: PropTypes.string.isRequired, | ||
value: PropTypes.string, | ||
label: PropTypes.string, | ||
error: PropTypes.string, | ||
onChange: PropTypes.func, | ||
type: PropTypes.string, | ||
button: PropTypes.element | ||
}; | ||
|
||
export default TextField; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parens superfluous on single param arrow functions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The style guide doesn't have an opinion on this.