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
Run eslint
  • Loading branch information
amaury1093 committed Jul 7, 2019
commit 0fcf5e330462921af02ec86bc55eb39b51ba81da
28 changes: 0 additions & 28 deletions .eslintrc

This file was deleted.

20 changes: 20 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module.exports = {
env: {
jest: true
},
extends: [
'prettier',
'prettier/standard',
'prettier/@typescript-eslint',
'semistandard'
],
parser: '@typescript-eslint/parser',
plugins: ['react', '@typescript-eslint'],
rules: {
// https://stackoverflow.com/questions/55280555/typescript-eslint-eslint-plugin-error-route-is-defined-but-never-used-no-un
'@typescript-eslint/no-unused-vars': 'error',
'no-unused-vars': 'off',
'react/jsx-uses-react': 1,
'react/jsx-uses-vars': 1
}
};
11 changes: 11 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"eslint.validate": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact"
],
"eslint.alwaysShowStatus": true,
"eslint.autoFixOnSave": true,
"editor.formatOnSave": true
}
2 changes: 1 addition & 1 deletion App/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ if (Constants.manifest.extra.sentryPublicDsn) {
Sentry.config(Constants.manifest.extra.sentryPublicDsn).install();
}

export function App() {
export function App () {
const [fontLoaded, setFontLoaded] = useState(false);
useEffect(() => {
Font.loadAsync({
Expand Down
2 changes: 1 addition & 1 deletion App/Screens/About/About.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import * as theme from '../../utils/theme';

interface AboutProps extends NavigationInjectedProps {}

export function About(props: AboutProps) {
export function About (props: AboutProps) {
const handleOpenAmaury = () =>
Linking.openURL('https://twitter.com/amaurymartiny');

Expand Down
2 changes: 1 addition & 1 deletion App/Screens/About/Box/Box.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import cigarette from '../../../../assets/images/cigarette.png';
import { i18n } from '../../../localization';
import * as theme from '../../../utils/theme';

export function Box() {
export function Box () {
return (
<View style={styles.box}>
<View style={styles.equivalence}>
Expand Down
2 changes: 1 addition & 1 deletion App/Screens/About/Language/Language.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import * as names from './names.json';
import { ApiContext } from '../../../stores';
import * as theme from '../../../utils/theme';

export function Language() {
export function Language () {
const { reloadApp } = useContext(ApiContext);

const handleValueChange = (itemValue: string) => {
Expand Down
3 changes: 1 addition & 2 deletions App/Screens/Details/Details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,13 @@ import { Header } from './Header';
import { i18n } from '../../localization';
import { ApiContext, CurrentLocationContext } from '../../stores';
import { distanceToStation, getCorrectLatLng } from '../../utils/station';
import * as theme from '../../utils/theme';

interface DetailsProps extends NavigationInjectedProps {}

// Holds the ref to the MapView.Marker representing the AQI station
let stationMarker: Marker | undefined;

export function Details(props: DetailsProps) {
export function Details (props: DetailsProps) {
const { navigation } = props;

const [showMap, setShowMap] = useState(false);
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 @@ -25,7 +25,7 @@ interface DistanceProps {
distance: number;
}

export function Distance(props: DistanceProps) {
export function Distance (props: DistanceProps) {
return (
<Banner elevated shadowPosition="top" style={styles.banner}>
<Text style={styles.distance}>
Expand Down
2 changes: 1 addition & 1 deletion App/Screens/Details/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ interface HeaderProps {
onBackClick: (event: GestureResponderEvent) => void;
}

export function Header(props: HeaderProps) {
export function Header (props: HeaderProps) {
const { onBackClick } = props;
const { api } = useContext(ApiContext);
const { currentLocation } = useContext(CurrentLocationContext);
Expand Down
2 changes: 1 addition & 1 deletion App/Screens/ErrorScreen/ErrorScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import * as theme from '../../utils/theme';

interface ErrorScreenProps extends NavigationInjectedProps {}

export function ErrorScreen(props: ErrorScreenProps) {
export function ErrorScreen (props: ErrorScreenProps) {
const { error } = useContext(ErrorContext);

return (
Expand Down
2 changes: 1 addition & 1 deletion App/Screens/Home/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ interface HeaderProps {
onChangeLocationClick: (event: GestureResponderEvent) => void;
}

export function Header(props: HeaderProps) {
export function Header (props: HeaderProps) {
const { api } = useContext(ApiContext)!;
const { currentLocation } = useContext(CurrentLocationContext);
const { onChangeLocationClick } = props;
Expand Down
12 changes: 6 additions & 6 deletions App/Screens/Home/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,21 @@ import * as theme from '../../utils/theme';

interface HomeProps extends NavigationInjectedProps {}

export function Home(props: HomeProps) {
export function Home (props: HomeProps) {
const { api } = useContext(ApiContext)!;
const { currentLocation } = useContext(CurrentLocationContext);

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

function goToAbout() {
function goToAbout () {
props.navigation.navigate('About');
}

function goToDetails() {
function goToDetails () {
props.navigation.navigate('Details');
}

function handleShare() {
function handleShare () {
return Share.share({
title: i18n.t('home_share_title'),
message: i18n.t('home_share_message', {
Expand Down Expand Up @@ -109,14 +109,14 @@ export function Home(props: HomeProps) {
);
};

function renderPresentPast() {
function renderPresentPast () {
const time = new Date().getHours();

if (time < 15) return i18n.t('home_common_you_ll_smoke');
return i18n.t('home_common_you_smoked');
}

function renderShit() {
function renderShit () {
if (api!.shootISmoke.cigarettes <= 1) return i18n.t('home_common_oh');

// Return a random swear word
Expand Down
2 changes: 1 addition & 1 deletion App/Screens/Home/SmallButton/SmallButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ interface SmallButtonProps extends TouchableOpacityProps {
text: string;
}

export function SmallButton({ text, icon, ...rest }: SmallButtonProps) {
export function SmallButton ({ text, icon, ...rest }: SmallButtonProps) {
return (
<TouchableOpacity style={styles.container} {...rest}>
{icon && (
Expand Down
4 changes: 2 additions & 2 deletions App/Screens/Home/SmokeVideo/SmokeVideo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { Dimensions, StyleSheet, View } from 'react-native';
import smokeVideo from '../../../../assets/video/smoke_bg_fafafc.mp4';
import { ApiContext } from '../../../stores';

export function SmokeVideo() {
export function SmokeVideo () {
const { api } = useContext(ApiContext)!;
const {
shootISmoke: { cigarettes }
Expand All @@ -41,7 +41,7 @@ export function SmokeVideo() {
);
}

function getVideoStyle(cigarettes: number) {
function getVideoStyle (cigarettes: number) {
if (cigarettes <= 1) return { backgroundColor: '#FFFFFFCC' };
if (cigarettes < 5) return { backgroundColor: '#FFFFFFAA' };
if (cigarettes < 15) return { backgroundColor: '#FFFFFF22' };
Expand Down
2 changes: 1 addition & 1 deletion App/Screens/Loading/Background.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ interface BackgroundProps {
style?: StyleProp<ViewStyle>;
}

export function Background(props: BackgroundProps) {
export function Background (props: BackgroundProps) {
return <View style={[styles.container, props.style]}>{props.children}</View>;
}

Expand Down
8 changes: 4 additions & 4 deletions App/Screens/Loading/Loading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ import * as theme from '../../utils/theme';
// The variable returned by setTimeout for longWaiting
let longWaitingTimeout: NodeJS.Timeout | null = null;

function clearLongWaiting() {
function clearLongWaiting () {
if (longWaitingTimeout) {
clearTimeout(longWaitingTimeout);
longWaitingTimeout = null;
}
}

export function Loading() {
export function Loading () {
const { api } = useContext(ApiContext);
const gps = useContext(GpsLocationContext);

Expand Down Expand Up @@ -62,7 +62,7 @@ export function Loading() {
);
}

function renderCough(index: number) {
function renderCough (index: number) {
return (
<Text key={index}>
{i18n.t('loading_title_cough')}
Expand All @@ -71,7 +71,7 @@ function renderCough(index: number) {
);
}

function renderText(longWaiting: boolean, gps?: Location, api?: Api) {
function renderText (longWaiting: boolean, gps?: Location, api?: Api) {
let coughs = 0; // Number of times to show "Cough..."
if (gps) ++coughs;
if (longWaiting) ++coughs;
Expand Down
6 changes: 3 additions & 3 deletions App/Screens/Screens.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { Search } from './Search';
import { Api, ApiContext, ErrorContext } from '../stores';
import * as theme from '../utils/theme';

function stackNavigatorOptions(initialRouteName: string) {
function stackNavigatorOptions (initialRouteName: string) {
return {
cardStyle: {
backgroundColor: theme.backgroundColor
Expand Down Expand Up @@ -84,7 +84,7 @@ const ErrorStack = createAppContainer(
)
);

export function Screens() {
export function Screens () {
const { api } = useContext(ApiContext);
const { error } = useContext(ErrorContext);

Expand All @@ -93,7 +93,7 @@ export function Screens() {
return <View style={theme.fullScreen}>{stack}</View>;
}

function renderScreen(api?: Api, error?: string) {
function renderScreen (api?: Api, error?: string) {
if (error) {
return <ErrorStack />;
}
Expand Down
3 changes: 1 addition & 2 deletions App/Screens/Search/Item/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
// 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 * as t from 'io-ts';
import React from 'react';
import { Image, StyleSheet, Text, TouchableOpacity, View } from 'react-native';

Expand All @@ -28,7 +27,7 @@ interface ItemProps {
onClick: (item: Location) => void;
}

export function Item(props: ItemProps) {
export function Item (props: ItemProps) {
const { item, onClick } = props;

const { city, country, county, _geoloc, locale_names: localeNames } = item;
Expand Down
20 changes: 10 additions & 10 deletions App/Screens/Search/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const AxiosResponseT = t.type({
})
});

function fetchAlgolia(search: string, gps?: LatLng) {
function fetchAlgolia (search: string, gps?: LatLng) {
return retry(algoliaUrls.length, status =>
pipe(
TE.rightIO(
Expand Down Expand Up @@ -104,11 +104,11 @@ function fetchAlgolia(search: string, gps?: LatLng) {
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 @@ -145,7 +145,7 @@ let typingTimeout: NodeJS.Timeout | null = null;

interface SearchProps extends NavigationInjectedProps {}

export function Search(props: SearchProps) {
export function Search (props: SearchProps) {
const { setCurrentLocation } = useContext(CurrentLocationContext);
const { setError } = useContext(ErrorContext);
const gps = useContext(GpsLocationContext);
Expand All @@ -157,7 +157,7 @@ export function Search(props: SearchProps) {
const [search, setSearch] = useState('');
const [hits, setHits] = useState<AlgoliaHit[]>([]);

function handleChangeSearch(s: string) {
function handleChangeSearch (s: string) {
setSearch(s);
setAlgoliaError(undefined);
setHits([]);
Expand Down Expand Up @@ -192,13 +192,13 @@ export function Search(props: SearchProps) {
}, 500);
}

function handleItemClick(item: Location) {
function handleItemClick (item: Location) {
// Reset everything when we choose a new location.
setCurrentLocation(item);
setError(undefined);
}

function renderItem({ item }: { item: AlgoliaHit }) {
function renderItem ({ item }: { item: AlgoliaHit }) {
return <Item item={item} onClick={handleItemClick} />;
}

Expand Down Expand Up @@ -226,7 +226,7 @@ export function Search(props: SearchProps) {
);
}

function renderInfoText(
function renderInfoText (
algoliaError: Error | undefined,
hits: AlgoliaHit[],
loading: boolean,
Expand All @@ -239,7 +239,7 @@ function renderInfoText(
return 'Waiting for results.';
}

function renderSeparator() {
function renderSeparator () {
return <View style={styles.separator} />;
}

Expand Down
2 changes: 1 addition & 1 deletion App/Screens/Search/SearchHeader/SearchHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ interface SearchHeaderProps {
search: string;
}

export function SearchHeader(props: SearchHeaderProps) {
export function SearchHeader (props: SearchHeaderProps) {
const { onChangeSearch, search } = props;

return (
Expand Down
Loading