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

fix: Small tweaks, including fix ErrorScreen #142

Merged
merged 2 commits into from
Jul 23, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Next Next commit
fix: Fix error screen not being able to move to search
  • Loading branch information
amaury1093 committed Jul 22, 2019
commit 8f8833f3493bef84e6729ecea960c72a39a30e67
16 changes: 8 additions & 8 deletions App/Screens/ErrorScreen/ErrorScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// along with Sh**t! I Smoke. If not, see <http:https://www.gnu.org/licenses/>.

import React, { useContext } from 'react';
import { Image, StyleSheet, Text, TouchableOpacity, View } from 'react-native';
import { Image, StyleSheet, Text, View } from 'react-native';
import { NavigationInjectedProps } from 'react-navigation';
import { scale } from 'react-native-size-matters';

Expand All @@ -41,13 +41,13 @@ export function ErrorScreen (props: ErrorScreenProps) {
{i18n.t('error_screen_error_cannot_load_cigarettes')}
</Text>
</View>
<TouchableOpacity onPress={() => props.navigation.navigate('Search')}>
<View style={styles.chooseOther}>
<Button style={styles.chooseOther} type="primary">
{i18n.t('error_screen_choose_other_location').toUpperCase()}
</Button>
</View>
</TouchableOpacity>
<Button
onPress={() => props.navigation.navigate('Search')}
style={styles.chooseOther}
type="primary"
>
{i18n.t('error_screen_choose_other_location').toUpperCase()}
</Button>
<Text style={theme.text}>{i18n.t('error_screen_error_description')}</Text>
<Text style={styles.errorMessage}>
{i18n.t('error_screen_error_message', { errorText: error })}
Expand Down
6 changes: 5 additions & 1 deletion App/Screens/Search/GpsItem/GpsItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export function GpsItem () {
const { setCurrentLocation } = useContext(CurrentLocationContext);
const gps = useContext(GpsLocationContext);

if (!gps) {
return null;
}

const handleClick = () => {
setCurrentLocation(gps);
};
Expand All @@ -35,7 +39,7 @@ export function GpsItem () {
description={i18n.t('search_current_location')}
icon="gps"
onPress={handleClick}
title={gps!.name || LOADING_TEXT}
title={gps.name || LOADING_TEXT}
/>
);
}
9 changes: 1 addition & 8 deletions App/Screens/Search/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@ import { AlgoliaHit, fetchAlgolia } from './fetchAlgolia';
import { AlgoliaItem } from './AlgoliaItem';
import { GpsItem } from './GpsItem';
import { SearchHeader } from './SearchHeader';
import {
CurrentLocationContext,
ErrorContext,
GpsLocationContext
} from '../../stores';
import { CurrentLocationContext, GpsLocationContext } from '../../stores';
import { Location } from '../../stores/fetchGpsPosition';
import { logFpError } from '../../util/fp';
import * as theme from '../../util/theme';
Expand All @@ -43,7 +39,6 @@ interface SearchProps extends NavigationInjectedProps {}

export function Search (props: SearchProps) {
const { isGps, setCurrentLocation } = useContext(CurrentLocationContext);
const { setError } = useContext(ErrorContext);
const gps = useContext(GpsLocationContext);

const [algoliaError, setAlgoliaError] = useState<Error | undefined>(
Expand Down Expand Up @@ -92,9 +87,7 @@ export function Search (props: SearchProps) {
}

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

function renderItem ({ item }: { item: AlgoliaHit }) {
Expand Down
5 changes: 3 additions & 2 deletions App/components/BoxButton/BoxButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,15 @@ const styles = StyleSheet.create({
opacity: 1
},
boxButton: {
...theme.elevationShadowStyle(3),
backgroundColor: 'white',
borderColor: 'rgba(0, 0, 0, 0.1)',
borderRadius: scale(12),
borderWidth: 1,
marginBottom: theme.spacing.tiny,
paddingHorizontal: theme.spacing.small,
paddingVertical: scale(4),
...theme.elevationShadowStyle(5)
paddingVertical: scale(4), // Padding for the shadow
shadowOpacity: 0.1
},
boxButtonText: {
...theme.shitText,
Expand Down
4 changes: 2 additions & 2 deletions App/components/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ interface ButtonProps extends TouchableOpacityProps {
}

export function Button (props: ButtonProps) {
const { children, icon, onPress, type, ...rest } = props;
const { children, icon, onPress, style, type, ...rest } = props;

return (
<TouchableOpacity
onPress={onPress}
style={[
styles.bigButton,
type && type === 'secondary' ? styles.secondary : styles.primary,
props.style
style
]}
{...rest}
>
Expand Down
1 change: 1 addition & 0 deletions App/stores/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export function ApiContextProvider ({ children }: ApiContextProviderProps) {

useEffect(() => {
setApi(undefined);
setError(undefined);

if (!currentLocation) {
return;
Expand Down
2 changes: 1 addition & 1 deletion App/stores/fetchApi/dataSources/aqicn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { pm25ToCigarettes } from './pm25ToCigarettes';
*/
export async function aqicn ({ latitude, longitude }: LatLng) {
const { data: response } = await axios.get(
`http:https://api.waqi.info/feed/geo:${latitude};${longitude}/?token=${
`http:https://api.waqi.info/feed2/geo:${latitude};${longitude}/?token=${
Constants.manifest.extra.waqiToken
}`,
{ timeout: 6000 }
Expand Down
2 changes: 1 addition & 1 deletion App/stores/fetchApi/dataSources/windWaqi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { pm25ToCigarettes } from './pm25ToCigarettes';
*/
export async function windWaqi ({ latitude, longitude }: LatLng) {
const { data: response } = await axios.get(
`https://wind.waqi.info/mapq/nearest?geo=1/${latitude}/${longitude}`,
`https://wind.waqi.info/ma2pq/nearest?geo=1/${latitude}/${longitude}`,
{ timeout: 6000 }
);

Expand Down
2 changes: 1 addition & 1 deletion App/util/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export function elevationShadowStyle (
shadowColor: 'black',
shadowOffset: {
width: 0,
height: scale((position === 'bottom' ? 1 : -1) * 0.5 * elevation)
height: scale((position === 'bottom' ? 1 : -1) * elevation)
},
shadowOpacity: 0.3,
shadowRadius: scale(0.8 * elevation)
Expand Down