Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement new design #49

Merged
merged 41 commits into from
Nov 17, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
f8b1918
Move About to Screen
amaury1093 Nov 15, 2018
43a619c
First batch of changes
amaury1093 Nov 16, 2018
cfa6fd4
Show details in details page
amaury1093 Nov 16, 2018
a47394d
Add banner on details
amaury1093 Nov 16, 2018
12058e2
Move Header inside Home
amaury1093 Nov 16, 2018
e0dc841
Use raw everywhere
amaury1093 Nov 16, 2018
5f46983
Add MST
amaury1093 Nov 16, 2018
9ff71df
Fix details page
amaury1093 Nov 16, 2018
0041874
Fix layout on homepage
amaury1093 Nov 16, 2018
b8810b0
Fix homepage
amaury1093 Nov 16, 2018
dbb158a
Fix About page
amaury1093 Nov 16, 2018
4d140d2
Add section in about
amaury1093 Nov 16, 2018
ecf62ab
Fix navigation transitions
amaury1093 Nov 16, 2018
51a8c6b
Fix shadows in Details
amaury1093 Nov 16, 2018
97481f0
Fix Search
amaury1093 Nov 16, 2018
98688d7
Use PureComponent everywhere
amaury1093 Nov 16, 2018
58389a9
Adjust cigarette position
amaury1093 Nov 16, 2018
b4a53e1
Fix scrolling on home
amaury1093 Nov 17, 2018
c54342d
Reorganize screens
amaury1093 Nov 17, 2018
72ddd59
Put error in mst
amaury1093 Nov 17, 2018
813ecf4
Fix button link
amaury1093 Nov 17, 2018
4f4d90a
Fix color
amaury1093 Nov 17, 2018
1766fe7
Small bugfixes
amaury1093 Nov 17, 2018
32776ed
Fix bug pollutants
amaury1093 Nov 17, 2018
035e881
Fix small bugs
amaury1093 Nov 17, 2018
d0f6526
Change meta info
amaury1093 Nov 17, 2018
6500c62
Update screenshots
amaury1093 Nov 17, 2018
fff94ff
Limit screenshot width
amaury1093 Nov 17, 2018
bc54c49
Fix limit width
amaury1093 Nov 17, 2018
fa06fed
Use img tag for screenshots
amaury1093 Nov 17, 2018
03072b0
Smaller images
amaury1093 Nov 17, 2018
cb27fbb
Images side by side
amaury1093 Nov 17, 2018
b1a1b97
Slightly bigger images
amaury1093 Nov 17, 2018
a6140c2
Bump version
amaury1093 Nov 17, 2018
59936ce
Fix lint
amaury1093 Nov 17, 2018
cf44b20
Add smoke video as separate component
amaury1093 Nov 17, 2018
e61502e
Fix header layout in details
amaury1093 Nov 17, 2018
401fb58
Add about text
amaury1093 Nov 17, 2018
5d3d51b
Add warning icons
amaury1093 Nov 17, 2018
9f2a907
Fix some designs
amaury1093 Nov 17, 2018
00252d2
Add font-awesome
amaury1093 Nov 17, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix details page
  • Loading branch information
amaury1093 committed Nov 16, 2018
commit 9ff71dfe5e366240c8a518653c4d78aee4cbc000
37 changes: 15 additions & 22 deletions App/Screens/Details/Details.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: GPL-3.0

import React, { Component } from 'react';
import { inject, observer } from 'mobx-react';
import { MapView } from 'expo';
import { StyleSheet, View } from 'react-native';
import truncate from 'truncate';
Expand All @@ -13,26 +14,16 @@ import homeIcon from '../../../assets/images/home.png';
import stationIcon from '../../../assets/images/station.png';
import * as theme from '../../utils/theme';

@inject('stores')
@observer
export class Details extends Component {
static navigationOptions = {
header: props => {
return (
<Header
{...props.screenProps}
elevated
onBackClick={props.navigation.pop}
showBackButton
style={styles.header}
/>
);
}
};
static navigationOptions = { header: null };

state = {
showMap: false
};

componentWillMount() {
componentDidMount() {
// Show map after 200ms for smoother screen transition
setTimeout(() => this.setState({ showMap: true }), 500);
}
Expand All @@ -49,7 +40,8 @@ export class Details extends Component {

render() {
const {
screenProps: { api, currentLocation }
navigation,
stores: { api, location }
} = this.props;
const { showMap } = this.state;

Expand All @@ -59,24 +51,25 @@ export class Details extends Component {
? api.attributions[0].name
: null,
title: api.city.name,
...getCorrectLatLng(currentLocation, {
...getCorrectLatLng(location.current, {
latitude: api.city.geo[0],
longitude: api.city.geo[1]
})
};

return (
<View style={styles.container}>
<Header onBackClick={navigation.pop} style={styles.header} />
<View style={styles.mapContainer}>
{showMap && (
<MapView
initialRegion={{
latitude: (currentLocation.latitude + station.latitude) / 2,
latitude: (location.current.latitude + station.latitude) / 2,
latitudeDelta:
Math.abs(currentLocation.latitude - station.latitude) * 2,
longitude: (currentLocation.longitude + station.longitude) / 2,
Math.abs(location.current.latitude - station.latitude) * 2,
longitude: (location.current.longitude + station.longitude) / 2,
longitudeDelta:
Math.abs(currentLocation.longitude - station.longitude) * 2
Math.abs(location.current.longitude - station.longitude) * 2
}}
onMapReady={this.handleMapReady}
style={styles.map}
Expand All @@ -91,14 +84,14 @@ export class Details extends Component {
/>
<MapView.Marker
color="blue"
coordinate={currentLocation}
coordinate={location.current}
image={homeIcon}
title="Your position"
/>
</MapView>
)}
</View>
<Distance api={api} currentLocation={currentLocation} />
<Distance />
</View>
);
}
Expand Down
22 changes: 9 additions & 13 deletions App/Screens/Details/Distance/Distance.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,25 @@
// SPDX-License-Identifier: GPL-3.0

import React, { Component } from 'react';
import haversine from 'haversine';
import { inject, observer } from 'mobx-react';
import { StyleSheet, Text } from 'react-native';

import { Banner } from '../../../components/Banner';
import { getCorrectLatLng } from '../../../utils/getCorrectLatLng';
import * as theme from '../../../utils/theme';

@inject('stores')
@observer
export class Distance extends Component {
render() {
const { api, currentLocation } = this.props;
const distance = Math.round(
haversine(
currentLocation,
getCorrectLatLng(currentLocation, {
latitude: api.city.geo[0],
longitude: api.city.geo[1]
})
)
);
const {
stores: { distanceToStation }
} = this.props;

return (
<Banner elevated="very" style={styles.banner}>
<Text style={styles.distance}>AQI STATION: {distance}KM AWAY</Text>
<Text style={styles.distance}>
AQI STATION: {distanceToStation}KM AWAY
</Text>
</Banner>
);
}
Expand Down
28 changes: 15 additions & 13 deletions App/Screens/Details/Header/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import React, { Component } from 'react';
import { Image, StyleSheet, Text, View } from 'react-native';
import { inject, observer } from 'mobx-react';

import { BackButton } from '../../../components/BackButton';
import changeLocation from '../../../../assets/images/changeLocation.png';
Expand Down Expand Up @@ -34,18 +35,23 @@ const weekdays = [
'Saturday'
];

@inject('stores')
@observer
export class Header extends Component {
static defaultProps = {
showChangeLocation: false
};

render() {
const { api, currentLocation, onBackClick } = this.props;
const {
onBackClick,
stores: { api }
} = this.props;

const lastUpdated =
api && api.debug && api.debug.sync ? new Date(api.debug.sync) : null;
const { dominantpol } = api;
const { no2, o3, pm10, pm25 } = api.iaqi || {};
api.time && api.time.v ? new Date(api.time.v * 1000) : null;
const {
dominantpol,
iaqi: { no2, o3, pm10, pm25 }
} = api;

console.log(api.iaqi);

return (
<View style={styles.container}>
Expand All @@ -55,11 +61,7 @@ export class Header extends Component {
<Image source={changeLocation} style={styles.changeLocation} />

<View>
<CurrentLocation
api={api}
currentLocation={currentLocation}
style={styles.currentLocation}
/>
<CurrentLocation style={styles.currentLocation} />
{lastUpdated &&
this.renderInfo(
'Latest Update:',
Expand Down
24 changes: 16 additions & 8 deletions App/Screens/Search/Search.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import React, { Component } from 'react';
import axios from 'axios';
import { Constants } from 'expo';
import { FlatList, Modal, StyleSheet, Text, View } from 'react-native';
import { inject, observer } from 'mobx-react';
import retry from 'async-retry';

import { BackButton } from '../../components/BackButton';
Expand All @@ -20,6 +21,8 @@ const algoliaUrls = [
'https://places-3.algolianet.com'
];

@inject('stores')
@observer
export class Search extends Component {
state = {
hasErrors: false, // Error from algolia
Expand All @@ -30,12 +33,17 @@ export class Search extends Component {

typingTimeout = null; // Timeout to detect when user stops typing

componentWillUnmount () {
componentWillUnmount() {
clearTimeout(this.typingTimeout);
}

fetchResults = async search => {
const { gps } = this.props;
const {
stores: {
location: { gps }
}
} = this.props;

try {
this.setState({ loading: true });
await retry(
Expand All @@ -57,11 +65,11 @@ export class Search extends Component {
Constants.manifest.extra.algoliaApplicationId &&
Constants.manifest.extra.algoliaApiKey
? {
'X-Algolia-Application-Id':
'X-Algolia-Application-Id':
Constants.manifest.extra.algoliaApplicationId,
'X-Algolia-API-Key':
'X-Algolia-API-Key':
Constants.manifest.extra.algoliaApiKey
}
}
: undefined,

timeout: 3000
Expand Down Expand Up @@ -94,12 +102,12 @@ export class Search extends Component {
this.props.onLocationChanged(item);
};

render () {
render() {
const { onRequestClose, ...rest } = this.props;
const { hits, search } = this.state;

return (
<Modal animationType='slide' onRequestClose={onRequestClose} {...rest}>
<Modal animationType="slide" onRequestClose={onRequestClose} {...rest}>
<View style={styles.container}>
<BackButton onClick={onRequestClose} style={styles.backButton} />
<SearchHeader
Expand All @@ -111,7 +119,7 @@ export class Search extends Component {
<FlatList
data={hits}
ItemSeparatorComponent={this.renderSeparator}
keyboardShouldPersistTaps='always'
keyboardShouldPersistTaps="always"
keyExtractor={({ objectID }) => objectID}
ListEmptyComponent={
<Text style={styles.noResults}>{this.renderInfoText()}</Text>
Expand Down
17 changes: 11 additions & 6 deletions App/components/CurrentLocation/CurrentLocation.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,36 @@
import React, { Component } from 'react';
import axios from 'axios';
import { Constants } from 'expo';
import { inject, observer } from 'mobx-react';
import { StyleSheet, Text } from 'react-native';

import * as theme from '../../utils/theme';

@inject('stores')
@observer
export class CurrentLocation extends Component {
state = {
locationName: 'Fetching...'
};

async componentDidMount() {
const { api, currentLocation } = this.props;
const {
stores: { api, location }
} = this.props;

// If our currentLocation already has a name (from Algolia), then we don't
// need Google Geocoding for the name
if (currentLocation.name) {
this.setState({ locationName: currentLocation.name.toUpperCase() });
if (location.name) {
this.setState({ locationName: location.name.toUpperCase() });
return;
}

try {
const { data } = await axios.get(
`https://us1.locationiq.com/v1/reverse.php?key=${
Constants.manifest.extra.locationIqKey
}&lat=${currentLocation.latitude}&lon=${
currentLocation.longitude
}&lat=${location.current.latitude}&lon=${
location.current.longitude
}&format=json`
);

Expand Down Expand Up @@ -59,7 +64,7 @@ export class CurrentLocation extends Component {
}

render() {
const { api, currentLocation, style, ...rest } = this.props;
const { stores, style, ...rest } = this.props;
const { locationName } = this.state;

return (
Expand Down
30 changes: 11 additions & 19 deletions App/stores/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,26 @@

import { types } from 'mobx-state-tree';

const pollutant = () =>
types.maybe(
types.model({
v: types.number
})
);

export const ApiStore = types.maybe(
types.model('ApiStore', {
aqi: types.number,
attributions: types.array(
types.model({
name: types.string,
url: types.string
})
),
city: types.model({
geo: types.array(types.number),
name: types.string,
url: types.string
}),
dominentpol: types.string,
iaqi: types.model({
h: pollutant(),
no2: pollutant(),
o3: pollutant(),
p: pollutant(),
pm10: pollutant(),
pm25: pollutant(),
so2: pollutant(),
t: pollutant(),
w: pollutant(),
wg: pollutant()
}),
iaqi: types.map(
types.model({
v: types.number
})
),
idx: types.number,
rawPm25: types.number,
time: types.model({
Expand Down
1 change: 1 addition & 0 deletions App/utils/dataSources/aqicn.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export const aqicn = async ({ latitude, longitude }) => {

return {
aqi: response.data.aqi,
attributions: response.data.attributions,
city: response.data.city,
dominentpol: response.data.dominentpol,
iaqi: response.data.iaqi,
Expand Down
1 change: 1 addition & 0 deletions App/utils/dataSources/windWaqi.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const windWaqi = async ({ latitude, longitude }) => {

return {
aqi: data.v,
attributions: [],
city: { geo: [+data.geo[0], +data.geo[1]], name: data.nlo },
dominentpol: data.pol,
iaqi: {
Expand Down