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

refactor: Convert everything to TypeScript #121

Merged
merged 43 commits into from
Jul 18, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
4385d36
Start ts
amaury1093 Jul 1, 2019
2ba71ab
Convert all files to TS
amaury1093 Jul 1, 2019
c911747
Make search work
amaury1093 Jul 6, 2019
1a02aaf
Make png import work
amaury1093 Jul 6, 2019
4805930
Add retry
amaury1093 Jul 6, 2019
e41774b
Make api call work
amaury1093 Jul 7, 2019
957ebaa
Add long waiting on Loading
amaury1093 Jul 7, 2019
8f8abe1
Make screens work
amaury1093 Jul 7, 2019
156a810
Make cigarettes work
amaury1093 Jul 7, 2019
3fa011d
Make header work
amaury1093 Jul 7, 2019
7d1db03
Reverse geocoding
amaury1093 Jul 7, 2019
7e3b3b8
Make details work
amaury1093 Jul 7, 2019
e137e0b
Make search work
amaury1093 Jul 7, 2019
4bcc494
Fix reload app
amaury1093 Jul 7, 2019
8f992fe
Make tests pass
amaury1093 Jul 7, 2019
0fcf5e3
Run eslint
amaury1093 Jul 7, 2019
5edd500
AqiHistory
amaury1093 Jul 9, 2019
f05a927
Add History manager back
amaury1093 Jul 9, 2019
704bb62
Start getting background location
amaury1093 Jul 9, 2019
9784aa1
Remove circular dependency
amaury1093 Jul 10, 2019
28b334c
Fix isSaveNeeded
amaury1093 Jul 10, 2019
2e54f5e
Add getData for testing
amaury1093 Jul 10, 2019
8462eeb
Add clearTable
amaury1093 Jul 10, 2019
60874bd
Fix tests
amaury1093 Jul 10, 2019
50af1ec
Update README
amaury1093 Jul 10, 2019
2a03a7f
Remove vs code settings
amaury1093 Jul 10, 2019
6135652
Fix too many requests
amaury1093 Jul 12, 2019
9886b4f
Add task to save to AsyncStorage
amaury1093 Jul 13, 2019
9206856
Return correct background fetch response
amaury1093 Jul 13, 2019
cf203ab
Refactor a bit the components
amaury1093 Jul 13, 2019
b1eed90
Make scroll work nicely
amaury1093 Jul 13, 2019
5fd5ccb
Add shadow on buttons
amaury1093 Jul 13, 2019
40f8848
Make stuff work
amaury1093 Jul 13, 2019
a516044
Weekly monthly
amaury1093 Jul 13, 2019
86d52a0
Calculate cigarettes
amaury1093 Jul 13, 2019
c1fed0b
Small fixes
amaury1093 Jul 13, 2019
bce6ecb
Small fixes
amaury1093 Jul 13, 2019
b12ee31
Small tweaks with icons
amaury1093 Jul 14, 2019
eb862cb
Add more dev info
amaury1093 Jul 16, 2019
050761c
Reverse geocode in search
amaury1093 Jul 16, 2019
d7ba1fd
Small tweaks
amaury1093 Jul 16, 2019
8c029ed
Small tweaks
amaury1093 Jul 17, 2019
d44d40b
Update icons
amaury1093 Jul 18, 2019
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
Make header work
  • Loading branch information
amaury1093 committed Jul 7, 2019
commit 3fa011d147a7d527de9f2baef7fbe6764c4cdf06
78 changes: 44 additions & 34 deletions App/Screens/Home/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,51 +14,61 @@
// You should have received a copy of the GNU General Public License
// along with Sh**t! I Smoke. If not, see <http:https://www.gnu.org/licenses/>.

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

import changeLocation from '../../../../assets/images/changeLocation.png';
import warning from '../../../../assets/images/warning.png';
import { CurrentLocation } from '../../../components/CurrentLocation';
import { i18n } from '../../../localization';
import { ApiContext, CurrentLocationContext } from '../../../stores';
import { distanceToStation, isStationTooFar } from '../../../utils/station';
import * as theme from '../../../utils/theme';

@inject('stores')
@observer
export class Header extends Component {
render () {
const {
onChangeLocationClick,
stores: { api, distanceToStation, isStationTooFar, location }
} = this.props;
interface HeaderProps {
onChangeLocationClick: (event: GestureResponderEvent) => void;
}

return (
<View style={styles.container}>
<View style={styles.content}>
<View style={styles.currentLocation}>
<CurrentLocation
api={api}
currentLocation={location.current}
numberOfLines={2}
/>
<View style={styles.distance}>
{isStationTooFar && (
<Image source={warning} style={styles.warning} />
)}
<Text style={theme.text}>
{i18n.t('home_header_air_quality_station_distance', { distanceToStation })}
</Text>
</View>
</View>
export function Header(props: HeaderProps) {
const api = useContext(ApiContext)!;
const { currentLocation } = useContext(CurrentLocationContext);
const { onChangeLocationClick } = props;

const distance = distanceToStation(currentLocation!, api);
const isTooFar = isStationTooFar(currentLocation!, api);

<TouchableOpacity onPress={onChangeLocationClick}>
<Image source={changeLocation} style={styles.changeLocation} />
</TouchableOpacity>
return (
<View style={styles.container}>
<View style={styles.content}>
<View style={styles.currentLocation}>
<CurrentLocation
api={api}
currentLocation={currentLocation!}
numberOfLines={2}
/>
<View style={styles.distance}>
{isTooFar && <Image source={warning} style={styles.warning} />}
<Text style={theme.text}>
{i18n.t('home_header_air_quality_station_distance', {
distanceToStation: distance
})}
</Text>
</View>
</View>

<TouchableOpacity onPress={onChangeLocationClick}>
<Image source={changeLocation} style={styles.changeLocation} />
</TouchableOpacity>
</View>
);
}
</View>
);
}

const styles = StyleSheet.create({
Expand Down
10 changes: 5 additions & 5 deletions App/Screens/Home/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import {
} from 'react-native';
import { NavigationInjectedProps } from 'react-navigation';

import { Cigarettes } from './Cigarettes';
// import { Header } from './Header';
import { Cigarettes } from '../../components/Cigarettes';
import { Header } from './Header';
import { i18n } from '../../localization';
import { SmallButton } from './SmallButton';
import { SmokeVideo } from './SmokeVideo';
Expand Down Expand Up @@ -154,16 +154,16 @@ export function Home(props: HomeProps) {
return (
<View style={styles.container}>
<SmokeVideo />
{/* <Header
<Header
onChangeLocationClick={() => props.navigation.navigate('Search')}
/> */}
/>
<ScrollView
bounces={false}
contentContainerStyle={styles.scrollContainer}
style={styles.scrollView}
>
<View style={styles.content}>
<Cigarettes />
<Cigarettes cigarettes={api.shootISmoke.cigarettes} />
<View style={styles.main}>{renderText()}</View>
</View>
<View style={styles.cta}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
import React from 'react';
import { Image, StyleSheet, View } from 'react-native';

import butt from '../../../../../assets/images/butt.png';
import buttVertical from '../../../../../assets/images/butt-vertical.png';
import head from '../../../../../assets/images/head.png';
import headVertical from '../../../../../assets/images/head-vertical.png';
import butt from '../../../../assets/images/butt.png';
import buttVertical from '../../../../assets/images/butt-vertical.png';
import head from '../../../../assets/images/head.png';
import headVertical from '../../../../assets/images/head-vertical.png';

export type CigaretteSize = 'small' | 'medium' | 'big';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@
// You should have received a copy of the GNU General Public License
// along with Sh**t! I Smoke. If not, see <http:https://www.gnu.org/licenses/>.

import React, { useContext } from 'react';
import React from 'react';
import { StyleSheet, View } from 'react-native';

import { Cigarette, CigaretteSize } from './Cigarette';
import { ApiContext } from '../../../stores';

export function Cigarettes() {
const {
shootISmoke: { cigarettes: realCigarettes }
} = useContext(ApiContext)!;
interface CigarettesProps {
cigarettes: number;
}

export function Cigarettes(props: CigarettesProps) {
const { cigarettes: realCigarettes } = props;
const cigarettes = Math.round(Math.min(realCigarettes, 63) * 10) / 10; // We don't show more than 63
// const cigarettes = 0.9; // Can change values here for testing

Expand Down
107 changes: 0 additions & 107 deletions App/components/CurrentLocation/CurrentLocation.ts

This file was deleted.

107 changes: 107 additions & 0 deletions App/components/CurrentLocation/CurrentLocation.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// Sh**t! I Smoke
// Copyright (C) 2018-2019 Marcelo S. Coelho, Amaury Martiny

// Sh**t! I Smoke is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Sh**t! I Smoke is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Sh**t! I Smoke. If not, see <http:https://www.gnu.org/licenses/>.

import React, { useState } from 'react';
import { StyleProp, StyleSheet, Text, TextStyle } from 'react-native';

import { Api, Location } from '../../stores';
import * as theme from '../../utils/theme';

interface CurrentLocationProps {
api: Api;
currentLocation: Location;
numberOfLines?: number;
style?: StyleProp<TextStyle>;
}

export function CurrentLocation(props: CurrentLocationProps) {
const [locationName, setLocationName] = useState(
props.currentLocation.name || 'Fetching...'
);

const { style, ...rest } = props;

return (
<Text style={[styles.title, style]} {...rest}>
{locationName}
</Text>
);
}

// async componentDidMount () {
// 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 (location.name) {
// this.setState({ locationName: location.name.toUpperCase() });
// return;
// }

// try {
// console.log(
// '<CurrentLocation> - componentDidMount - Fetching reverse geocoding'
// );
// const { data } = await axios.get(
// `https://us1.locationiq.com/v1/reverse.php?key=${
// Constants.manifest.extra.locationIqKey
// }&lat=${location.current.latitude}&lon=${
// location.current.longitude
// }&format=json`
// );

// // If we got data from the Google Geocoding service, then we use that one
// if (!data || !data.address || !data.display_name) {
// throw new Error('No data from LocationIQ.');
// }

// console.log('<CurrentLocation> - componentDidMount - Got result');

// // We format the formatted_address to remove postal code and street number for privacy reasons
// const postalCode = data.address.postcode;
// const streetNumber = data.address.house_number;

// this.setState({
// locationName: data.display_name
// .replace(postalCode, '')
// .replace(streetNumber, '')
// .replace(/^,/, '') // Remove starting comma
// .replace(', ,', ',') // Remove unnecessary commas
// .replace(/ +/g, ' ') // Remove double spaces
// .replace(' ,', ',') // Self-explanatory
// .trim()
// .toUpperCase()
// });
// } catch (error) {
// console.log('<CurrentLocation> - componentDidMount - Error', error);

// // Show AQI station name if we don't have reverse geocoding data
// this.setState({
// locationName:
// api.city && api.city.name
// ? api.city.name.toUpperCase()
// : 'UNKNOWN AQI STATION'
// });
// }
// }

const styles = StyleSheet.create({
title: {
...theme.title
}
});