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
Refactor a bit the components
  • Loading branch information
amaury1093 committed Jul 13, 2019
commit cf203abfbc6208293a6cd0311b92a56264c60079
11 changes: 6 additions & 5 deletions App/Screens/About/About.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ import {
Text,
View
} from 'react-native';
import { scale } from 'react-native-size-matters';
import { NavigationInjectedProps } from 'react-navigation';

import { Box } from './Box';
import { BackButton } from '../../components/BackButton';
import { BackButton } from '../../components';
import { Dev } from './Dev';
import { Language } from './Language';
import { i18n } from '../../localization';
Expand Down Expand Up @@ -55,7 +56,7 @@ export function About (props: AboutProps) {
const { navigation } = props;
return (
<ScrollView style={theme.withPadding}>
<BackButton onClick={() => navigation.pop()} style={styles.backButton} />
<BackButton onPress={() => navigation.pop()} style={styles.backButton} />

<View style={styles.section}>
<Text style={styles.h2}>
Expand Down Expand Up @@ -161,7 +162,7 @@ export function About (props: AboutProps) {
const styles = StyleSheet.create({
articleLink: {
...theme.text,
fontSize: 8
fontSize: scale(8)
},
backButton: {
marginBottom: theme.spacing.normal,
Expand All @@ -175,9 +176,9 @@ const styles = StyleSheet.create({
},
h2: {
...theme.title,
fontSize: 20,
fontSize: scale(20),
letterSpacing: 0,
lineHeight: 24,
lineHeight: scale(24),
marginBottom: theme.spacing.small
},
language: {
Expand Down
2 changes: 1 addition & 1 deletion App/Screens/Details/Distance/Distance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import React from 'react';
import { StyleSheet, Text } from 'react-native';

import { Banner } from '../../../components/Banner';
import { Banner } from '../../../components';
import { i18n } from '../../../localization';
import * as theme from '../../../util/theme';

Expand Down
9 changes: 4 additions & 5 deletions App/Screens/Details/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ import {
} from 'react-native';

import locationIcon from '../../../../assets/images/location.png';
import { BackButton } from '../../../components/BackButton';
import { CurrentLocation } from '../../../components/CurrentLocation';
import { BackButton, CurrentLocation } from '../../../components';
import { i18n } from '../../../localization';
import { ApiContext, CurrentLocationContext } from '../../../stores';
import * as theme from '../../../util/theme';
Expand All @@ -50,7 +49,7 @@ export function Header (props: HeaderProps) {

return (
<View style={styles.container}>
<BackButton onClick={onBackClick} style={styles.backButton} />
<BackButton onPress={onBackClick} style={styles.backButton} />

<View style={styles.layout}>
<Image source={locationIcon} style={styles.changeLocation} />
Expand Down Expand Up @@ -112,7 +111,7 @@ const styles = StyleSheet.create({
...theme.elevatedLevel1('bottom'),
...theme.withPadding,
backgroundColor: 'white',
paddingBottom: 15,
paddingBottom: theme.spacing.small,
paddingTop: theme.spacing.normal,
zIndex: 1
},
Expand All @@ -128,7 +127,7 @@ const styles = StyleSheet.create({
},
label: {
color: theme.primaryColor,
fontFamily: theme.boldFont
fontFamily: theme.gothamBlack
},
layout: {
flexDirection: 'row'
Expand Down
9 changes: 5 additions & 4 deletions App/Screens/ErrorScreen/ErrorScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
import React, { useContext } from 'react';
import { Image, StyleSheet, Text, TouchableOpacity, View } from 'react-native';
import { NavigationInjectedProps } from 'react-navigation';
import { scale } from 'react-native-size-matters';

import errorPicture from '../../../assets/images/error.png';
import { Button } from '../../components';
import { i18n } from '../../localization';
import { ErrorContext } from '../../stores';
import * as theme from '../../util/theme';
Expand All @@ -41,9 +43,9 @@ export function ErrorScreen (props: ErrorScreenProps) {
</View>
<TouchableOpacity onPress={() => props.navigation.navigate('Search')}>
<View style={styles.chooseOther}>
<Text style={theme.bigButtonText}>
<Button style={styles.chooseOther}>
{i18n.t('error_screen_choose_other_location').toUpperCase()}
</Text>
</Button>
</View>
</TouchableOpacity>
<Text style={theme.text}>{i18n.t('error_screen_error_description')}</Text>
Expand All @@ -56,7 +58,6 @@ export function ErrorScreen (props: ErrorScreenProps) {

const styles = StyleSheet.create({
chooseOther: {
...theme.bigButton,
marginVertical: theme.spacing.normal
},
container: {
Expand All @@ -67,7 +68,7 @@ const styles = StyleSheet.create({
},
errorMessage: {
...theme.text,
fontSize: 10,
fontSize: scale(10),
marginTop: theme.spacing.small
},
errorText: {
Expand Down
57 changes: 57 additions & 0 deletions App/Screens/Home/Frequency/Frequency.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// 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 from 'react';
import { StyleSheet, View } from 'react-native';

import { BoxButton } from '../../../components';
import * as theme from '../../../util/theme';

const FREQUENCY = {
daily: undefined,
weekly: new Date(),
monthly: new Date()
};
type Frequency = keyof typeof FREQUENCY;

interface FrequencyProps {
onChangeFrequency: (frequency: Frequency) => void;
}

export function Frequency (props: FrequencyProps) {
return (
<View style={styles.container}>
<BoxButton
onPress={() => props.onChangeFrequency('daily')}
style={styles.boxButton}
>
daily
</BoxButton>
<BoxButton style={styles.boxButton}>weekly</BoxButton>
<BoxButton style={styles.boxButton}>monthly</BoxButton>
</View>
);
}

const styles = StyleSheet.create({
boxButton: {
marginRight: theme.spacing.tiny
},
container: {
flexDirection: 'row',
marginTop: theme.spacing.tiny
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
// 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/>.

export * from './SmallButton';
export * from './Frequency';
8 changes: 2 additions & 6 deletions App/Screens/Home/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {

import changeLocation from '../../../../assets/images/changeLocation.png';
import warning from '../../../../assets/images/warning.png';
import { CurrentLocation } from '../../../components/CurrentLocation';
import { CurrentLocation } from '../../../components';
import { i18n } from '../../../localization';
import { ApiContext, CurrentLocationContext } from '../../../stores';
import { distanceToStation, isStationTooFar } from '../../../util/station';
Expand Down Expand Up @@ -91,11 +91,7 @@ const styles = StyleSheet.create({
},
distance: {
flexDirection: 'row',
marginTop: 11
},
title: {
...theme.title,
fontSize: 15
marginTop: theme.spacing.tiny
},
warning: {
marginRight: theme.spacing.tiny
Expand Down
63 changes: 22 additions & 41 deletions App/Screens/Home/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,13 @@
// along with Sh**t! I Smoke. If not, see <http:https://www.gnu.org/licenses/>.

import React, { useContext } from 'react';
import {
ScrollView,
Share,
StyleSheet,
Text,
TouchableOpacity,
View
} from 'react-native';
import { ScrollView, Share, StyleSheet, Text, View } from 'react-native';
import { NavigationInjectedProps } from 'react-navigation';

import { Cigarettes } from '../../components/Cigarettes';
import { Button, Cigarettes } from '../../components';
import { Frequency } from './Frequency';
import { Header } from './Header';
import { i18n } from '../../localization';
import { SmallButton } from './SmallButton';
import { SmokeVideo } from './SmokeVideo';
import { ApiContext, CurrentLocationContext } from '../../stores';
import swearWords from './swearWords';
Expand Down Expand Up @@ -63,48 +56,34 @@ export function Home (props: HomeProps) {
const renderBigButton = () => {
if (isTooFar) {
return (
<TouchableOpacity onPress={goToAbout}>
<View style={theme.bigButton}>
<Text style={theme.bigButtonText}>
{i18n.t('home_btn_why_is_station_so_far').toUpperCase()}
</Text>
</View>
</TouchableOpacity>
<Button onPress={goToAbout}>
{i18n.t('home_btn_why_is_station_so_far').toUpperCase()}
</Button>
);
}

return (
<TouchableOpacity onPress={goToDetails}>
<View style={theme.bigButton}>
<Text style={theme.bigButtonText}>
{i18n.t('home_btn_see_detailed_info').toUpperCase()}
</Text>
</View>
</TouchableOpacity>
<Button onPress={goToDetails}>
{i18n.t('home_btn_see_detailed_info').toUpperCase()}
</Button>
);
};

const renderFooter = () => {
return (
<View style={styles.smallButtons}>
{isTooFar ? (
<SmallButton
icon="plus-circle"
text={i18n.t('home_btn_more_details').toUpperCase()}
onPress={goToDetails}
/>
<Button icon="plus-circle" onPress={goToDetails} type="secondary">
{i18n.t('home_btn_more_details').toUpperCase()}
</Button>
) : (
<SmallButton
icon="question-circle"
text={i18n.t('home_btn_faq_about').toUpperCase()}
onPress={goToAbout}
/>
<Button icon="question-circle" onPress={goToAbout} type="secondary">
{i18n.t('home_btn_faq_about').toUpperCase()}
</Button>
)}
<SmallButton
icon="share-alt"
text={i18n.t('home_btn_share').toUpperCase()}
onPress={handleShare}
/>
<Button icon="share-alt" onPress={handleShare} type="secondary">
{i18n.t('home_btn_share').toUpperCase()}
</Button>
</View>
);
};
Expand Down Expand Up @@ -164,7 +143,10 @@ export function Home (props: HomeProps) {
>
<View style={styles.content}>
<Cigarettes cigarettes={api!.shootISmoke.cigarettes} />
<View style={styles.main}>{renderText()}</View>
<View style={styles.main}>
{renderText()}
<Frequency onChangeFrequency={() => {}} />
</View>
</View>
<View style={styles.cta}>
{isTooFar && (
Expand Down Expand Up @@ -219,7 +201,6 @@ const styles = StyleSheet.create({
smallButtons: {
flexDirection: 'row',
justifyContent: 'space-around',
marginBottom: 2 * theme.spacing.normal,
marginTop: theme.spacing.normal
}
});
9 changes: 5 additions & 4 deletions App/Screens/Search/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ import * as TE from 'fp-ts/lib/TaskEither';
import * as t from 'io-ts';
import { failure } from 'io-ts/lib/PathReporter';
import { FlatList, StyleSheet, Text, View } from 'react-native';
import { scale } from 'react-native-size-matters';
import { NavigationInjectedProps } from 'react-navigation';
import Sentry from 'sentry-expo';

import { BackButton } from '../../components/BackButton';
import { BackButton } from '../../components';
import { Item } from './Item';
import { SearchHeader } from './SearchHeader';
import {
Expand Down Expand Up @@ -209,7 +210,7 @@ export function Search (props: SearchProps) {
return (
<View style={styles.container}>
<BackButton
onClick={() => props.navigation.pop()}
onPress={() => props.navigation.pop()}
style={styles.backButton}
/>
<SearchHeader onChangeSearch={handleChangeSearch} search={search} />
Expand Down Expand Up @@ -250,7 +251,7 @@ function renderSeparator () {
const styles = StyleSheet.create({
backButton: {
...theme.withPadding,
marginVertical: 18
marginVertical: theme.spacing.normal
},
container: {
flexGrow: 1
Expand All @@ -266,6 +267,6 @@ const styles = StyleSheet.create({
separator: {
backgroundColor: '#D2D2D2',
height: 1,
marginLeft: 17 + 22 + 17 // Margin + imgWidth + margin
marginLeft: scale(17 + 22 + 17) // Margin + imgWidth + margin
}
});
2 changes: 1 addition & 1 deletion App/Screens/Search/SearchHeader/SearchHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import React from 'react';
import { Image, StyleSheet, TextInput } from 'react-native';

import searchIcon from '../../../../assets/images/search.png';
import { Banner } from '../../../components/Banner';
import { Banner } from '../../../components';
import { i18n } from '../../../localization';
import * as theme from '../../../util/theme';

Expand Down
4 changes: 2 additions & 2 deletions App/components/BackButton/BackButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import * as theme from '../../util/theme';
import { i18n } from '../../localization';

interface BackButtonProps {
onClick: (event: GestureResponderEvent) => void;
onPress: (event: GestureResponderEvent) => void;
style?: StyleProp<ViewStyle>; // FIXME any
}

Expand All @@ -42,7 +42,7 @@ export function BackButton (props: BackButtonProps) {
<View style={style}>
<TouchableOpacity
hitSlop={{ top: 20, bottom: 20, left: 20, right: 20 }}
onPress={props.onClick}
onPress={props.onPress}
style={styles.backButton}
>
<Image source={backIcon} />
Expand Down
Loading