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

feat: Implement miles/kilometer selector #252

Merged
merged 11 commits into from
Oct 6, 2019
Prev Previous commit
fix: resolve lint errors
  • Loading branch information
matepapp committed Oct 6, 2019
commit a9bedb40877bacce26c4ef3d5945353b7496abae
46 changes: 23 additions & 23 deletions App/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,60 +14,60 @@
// 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 Font from 'expo-font'
import Constants from 'expo-constants'
import React, { useEffect, useState } from 'react'
import { AppState } from 'react-native'
import * as Sentry from 'sentry-expo'
import * as Font from 'expo-font';
import Constants from 'expo-constants';
import React, { useEffect, useState } from 'react';
import { AppState } from 'react-native';
import * as Sentry from 'sentry-expo';

import { Screens } from './Screens'
import { Background as LoadingBackground } from './Screens/Loading/Background'
import { Screens } from './Screens';
import { Background as LoadingBackground } from './Screens/Loading/Background';
import {
ApiContextProvider,
DistanceUnitProvider,
ErrorContextProvider,
FrequencyContextProvider,
LocationContextProvider,
} from './stores'
import { setupAmplitude, track } from './util/amplitude'
LocationContextProvider
} from './stores';
import { setupAmplitude, track } from './util/amplitude';

// Add Sentry if available
if (Constants.manifest.extra.sentryPublicDsn) {
Sentry.init({
dsn: Constants.manifest.extra.sentryPublicDsn,
debug: true,
})
debug: true
});

if (Constants.manifest.revisionId) {
Sentry.setRelease(Constants.manifest.revisionId)
Sentry.setRelease(Constants.manifest.revisionId);
}
}

export function App () {
const [ready, setReady] = useState(false)
const [ready, setReady] = useState(false);
useEffect(() => {
Promise.all([
Font.loadAsync({
'gotham-black': require('../assets/fonts/Gotham-Black.ttf'),
'gotham-book': require('../assets/fonts/Gotham-Book.ttf'),
'gotham-book': require('../assets/fonts/Gotham-Book.ttf')
}),
// Add Amplitude if available
setupAmplitude(),
setupAmplitude()
])

.then(() => setReady(true))
.catch(console.error)
}, [])
.catch(console.error);
}, []);

useEffect(() => {
AppState.addEventListener('change', state => {
if (state === 'active') {
track('APP_REFOCUS')
track('APP_REFOCUS');
} else if (state === 'background') {
track('APP_EXIT')
track('APP_EXIT');
}
})
}, [])
});
}, []);

return ready ? (
<ErrorContextProvider>
Expand All @@ -83,5 +83,5 @@ export function App () {
</ErrorContextProvider>
) : (
<LoadingBackground />
)
);
}
52 changes: 26 additions & 26 deletions App/Screens/Home/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,31 @@
// 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 { GestureResponderEvent, Image, StyleSheet, Text, View } from 'react-native'
import { scale } from 'react-native-size-matters'
import React, { useContext } from 'react';
import { GestureResponderEvent, Image, StyleSheet, Text, View } from 'react-native';
import { scale } from 'react-native-size-matters';

import alert from '../../../../assets/images/alert.png'
import { ChangeLocation, CurrentLocation } from '../../../components'
import { i18n } from '../../../localization'
import { ApiContext, CurrentLocationContext } from '../../../stores'
import { distanceToStation, isStationTooFar } from '../../../util/station'
import { useDistanceUnit } from '../../../stores/distanceUnit'
import * as theme from '../../../util/theme'
import alert from '../../../../assets/images/alert.png';
import { ChangeLocation, CurrentLocation } from '../../../components';
import { i18n } from '../../../localization';
import { ApiContext, CurrentLocationContext } from '../../../stores';
import { distanceToStation, isStationTooFar } from '../../../util/station';
import { useDistanceUnit } from '../../../stores/distanceUnit';
import * as theme from '../../../util/theme';

interface HeaderProps {
onChangeLocationClick: (event: GestureResponderEvent) => void
}

export function Header (props: HeaderProps) {
const { api } = useContext(ApiContext)!
const { currentLocation, isGps } = useContext(CurrentLocationContext)
const { distanceUnit, localizedDistanceUnit } = useDistanceUnit()
const { onChangeLocationClick } = props
const { api } = useContext(ApiContext)!;
const { currentLocation, isGps } = useContext(CurrentLocationContext);
const { distanceUnit, localizedDistanceUnit } = useDistanceUnit();
const { onChangeLocationClick } = props;

const shortDistanceUnit = localizedDistanceUnit('short')
const distance = distanceToStation(currentLocation!, api!, distanceUnit)
const isTooFar = isStationTooFar(currentLocation!, api!)
const shortDistanceUnit = localizedDistanceUnit('short');
const distance = distanceToStation(currentLocation!, api!, distanceUnit);
const isTooFar = isStationTooFar(currentLocation!, api!);

return (
<View style={styles.container}>
Expand All @@ -49,7 +49,7 @@ export function Header (props: HeaderProps) {
<Text style={styles.distanceText}>
{i18n.t('home_header_air_quality_station_distance', {
distanceToStation: distance,
distanceUnit: shortDistanceUnit,
distanceUnit: shortDistanceUnit
})}{' '}
{!isGps && i18n.t('home_header_from_search')}
</Text>
Expand All @@ -58,31 +58,31 @@ export function Header (props: HeaderProps) {

<ChangeLocation onPress={onChangeLocationClick} />
</View>
)
);
}

const styles = StyleSheet.create({
container: {
...theme.withPadding,
alignItems: 'center',
flexDirection: 'row',
paddingTop: theme.spacing.normal,
paddingTop: theme.spacing.normal
},
currentLocation: {
flex: 1,
marginRight: theme.spacing.mini,
marginRight: theme.spacing.mini
},
distance: {
alignItems: 'center',
flexDirection: 'row',
marginTop: theme.spacing.mini,
marginTop: theme.spacing.mini
},
distanceText: {
...theme.text,
flex: 1,
flex: 1
},
warning: {
marginRight: theme.spacing.mini,
marginTop: scale(-2), // FIXME We shouldn't need that, with `alignItems: 'center'` on .distance
},
})
marginTop: scale(-2) // FIXME We shouldn't need that, with `alignItems: 'center'` on .distance
}
});
2 changes: 1 addition & 1 deletion App/stores/distanceUnit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ export function DistanceUnitProvider ({ children }: { children: ReactNode }) {
{children}
</Context.Provider>
);
};
}

export const useDistanceUnit = () => useContext(Context);