Center new work item on user

This commit is contained in:
John Lyon-Smith
2018-05-16 13:15:56 -07:00
parent 23d4a95bd6
commit 15bc64a42b
3 changed files with 32 additions and 4 deletions

View File

@@ -6,6 +6,11 @@ import autobind from "autobind-decorator"
export class Geolocation extends Component {
static propTypes = {
onUpdate: PropTypes.func.isRequired,
watch: PropTypes.bool,
}
static defaultProps = {
watch: true,
}
constructor(props) {
@@ -16,9 +21,12 @@ export class Geolocation extends Component {
componentDidMount() {
navigator.geolocation.getCurrentPosition((position) => {
this.props.onUpdate(position)
this.watchId = navigator.geolocation.watchPosition((position) =>
this.props.onUpdate(position)
)
if (this.props.watch) {
this.watchId = navigator.geolocation.watchPosition((position) =>
this.props.onUpdate(position)
)
}
})
}