This repository has been archived by the owner on Jul 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #148 from wbprice/get-location
Get location
- Loading branch information
Showing
20 changed files
with
499 additions
and
10 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
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); | ||
}); | ||
} | ||
|
||
}; | ||
|
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use strict'; | ||
|
||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
class Hr extends Component { | ||
render() { | ||
const hrLineStyle = { | ||
background: this.props.background | ||
}; | ||
|
||
return ( | ||
<div className="hr"> | ||
<div className="hr-line" style={hrLineStyle}></div> | ||
{ | ||
this.props.label && | ||
<label className="hr-label">{this.props.label}</label> | ||
} | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
Hr.propTypes = { | ||
label: PropTypes.string, | ||
background: PropTypes.string | ||
}; | ||
|
||
export default Hr; |
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,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.address} | ||
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; |
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,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); |
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,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'}`}> | ||
<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; |
Oops, something went wrong.