Skip to content

Commit

Permalink
Added address info to map
Browse files Browse the repository at this point in the history
  • Loading branch information
Teemu Taskula committed Nov 26, 2017
1 parent d18c047 commit 750781a
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 24 deletions.
8 changes: 5 additions & 3 deletions client/features/evaluate/Card.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { Component } from 'react';
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import styled from 'styled-components/native';
import Icon from 'react-native-vector-icons/FontAwesome';
Expand Down Expand Up @@ -26,15 +26,15 @@ const propTypes = {

const { width: windowWidth } = Dimensions.get('window');

class Card extends Component {
class Card extends PureComponent {
render() {
const { item, onOk, onDecline, onAddComment } = this.props;

return (
<CardWrapper>
<CardImage
source={{ uri: item.image }}
resizeMode="cover"
resizeMode="contain"
/>
<Details>
<Icon name="clock-o" size={18} color="#444" />
Expand Down Expand Up @@ -101,6 +101,7 @@ const CardWrapper = styled.View`
shadow-color: #000;
shadow-offset: 0px 4px;
padding-bottom: 16px;
elevation: 3;
`;

const CardImage = styled.Image`
Expand Down Expand Up @@ -146,6 +147,7 @@ const Details = styled.View`
padding-horizontal: 16px;
flex-direction: row;
align-items: center;
justify-content: center;
`;

const AddComment = styled.View`
Expand Down
23 changes: 9 additions & 14 deletions client/features/evaluate/evaluate.screen.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ class EvaluateScreen extends Component {
constructor(props) {
super(props);
this.state = {
swipes: 0,
commentedItem: null,
dataSource: props.marks,
dataSource: [...props.marks],
};
}

Expand All @@ -45,34 +44,26 @@ class EvaluateScreen extends Component {

handleOk = item => {
if (this.deckSwiper) {
this.incSwipes();
this.props.addMarkType({ id: item.id, type: 'ok' });
this.deckSwiper._root.swipeRight();
this.props.addMarkType({ id: item.id, type: 'ok' });
}
}

handleDecline = item => {
if (this.deckSwiper) {
this.incSwipes();
this.props.addMarkType({ id: item.id, type: 'repair' });
this.deckSwiper._root.swipeLeft();
this.props.addMarkType({ id: item.id, type: 'repair' });
}
}

handleSwipeLeft = item => {
this.incSwipes();
this.props.addMarkType({ id: item.id, type: 'repair' });
}

handleSwipeRight = item => {
this.incSwipes();
this.props.addMarkType({ id: item.id, type: 'ok' });
}

incSwipes = () => {
this.setState(prev => ({ swipes: prev.swipes + 1 }));
}

finishEvaluation = () => {
this.props.navigation.navigate('Optimize');
}
Expand All @@ -97,8 +88,12 @@ class EvaluateScreen extends Component {
}

render() {
const { marksByid } = this.props;
const { isModalVisible, commentedItem, swipes, dataSource } = this.state;
const { marksByid, marks } = this.props;
const { isModalVisible, commentedItem, dataSource } = this.state;
const swipes = marks.reduce((sum, mark) => {
if (mark.type === 'repair' || mark.type === 'ok') sum += 1;
return sum;
}, 0);

return (
<EvaluateScreenWrapper>
Expand Down
4 changes: 3 additions & 1 deletion client/features/mark/mark.ducks.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ function* handleCapturePhoto({ payload }) {
if (!demoCoords.length) return;

const id = guid();
// const geo = demoCoords.pop();
const geo = demoCoords[0];

// post image and geo location to server
Expand All @@ -104,6 +103,9 @@ function* handleCapturePhoto({ payload }) {
}

function* handleMarkReceive({ payload }) {
// Consume coords
if (demoCoords.length) demoCoords.shift();

const {
id,
timestamp,
Expand Down
3 changes: 2 additions & 1 deletion client/features/mark/mark.screen.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const propTypes = {
marks: PropTypes.array.isRequired,
};

const PHOTO_INTERVAL = 2000;
const PHOTO_INTERVAL = 1000;

class MarkScreen extends Component {
componentDidMount() {
Expand Down Expand Up @@ -68,6 +68,7 @@ class MarkScreen extends Component {
captureQuality={Camera.constants.CaptureQuality['480p']}
orientation="portrait"
keepAwake
fixOrientation
>
<Button onPress={this.finishMarking} lg success>
<Text size="18px">
Expand Down
35 changes: 31 additions & 4 deletions client/features/optimize/optimize.screen.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ const propTypes = {
class OptimizeScreen extends Component {
state = {
route: null,
adById: null,
}

componentWillMount() {
this.getAddresses();
this.getDirections();
}

Expand All @@ -33,6 +35,28 @@ class OptimizeScreen extends Component {
return [marks[0].geo.long, marks[0].geo.lat];
}

getAddresses = () => {
const { marks } = this.props;
const promises = [];

marks.forEach(({ geo, id }) => {
promises.push(
fetch(`http://nominatim.openstreetmap.org/reverse?format=json&lat=${geo.lat}&lon=${geo.long}&zoom=18&addressdetails=1`) // eslint-disable-line
.then(res => res.json())
.then(({ address }) => ({ address, id }))
);
});

Promise.all(promises)
.then(addresses => {
const adById = {};
addresses.forEach(({ address, id }) => {
adById[id] = `${address.road}, ${address.suburb}, ${address.city}`;
});
this.setState({ adById });
});
}

getDirections = () => {
const { marks } = this.props;

Expand Down Expand Up @@ -70,10 +94,12 @@ class OptimizeScreen extends Component {
}

render() {
const { route } = this.state;
const { route, adById } = this.state;
const { marks } = this.props;
const center = this.getCenterCoord();

if (!adById) return null;

return (
<OptimizeScreenWrapper>
<Mapbox.MapView
Expand All @@ -88,14 +114,15 @@ class OptimizeScreen extends Component {

{marks.map(mark =>
<Mapbox.PointAnnotation
key={`${mark.id}_${mark.geo.lat}`}
id="markPoint"
key={`${mark.id}`}
id={`${mark.id}`}
coordinate={[mark.geo.long, mark.geo.lat]}
title={adById[mark.id]}
>
<Dot>
<DotFill type={mark.type} />
</Dot>
<Mapbox.Callout title="Look! An annotation!" />
<Mapbox.Callout title={adById[mark.id]} />
</Mapbox.PointAnnotation>
)}

Expand Down
2 changes: 1 addition & 1 deletion client/middleware/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createClient } from './client';

// const wsUrl = '2fd5cbca.ngrok.io';
const wsUrl = 'e9ba5d43.ngrok.io';
const wsUrl = 'ca5b2adf.ngrok.io';

// Export middleware function
export default () => store => {
Expand Down

0 comments on commit 750781a

Please sign in to comment.