From 8f8833f3493bef84e6729ecea960c72a39a30e67 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Mon, 22 Jul 2019 20:03:18 +0200 Subject: [PATCH 1/2] fix: Fix error screen not being able to move to search --- App/Screens/ErrorScreen/ErrorScreen.tsx | 16 ++++++++-------- App/Screens/Search/GpsItem/GpsItem.tsx | 6 +++++- App/Screens/Search/Search.tsx | 9 +-------- App/components/BoxButton/BoxButton.tsx | 5 +++-- App/components/Button/Button.tsx | 4 ++-- App/stores/api.tsx | 1 + App/stores/fetchApi/dataSources/aqicn.ts | 2 +- App/stores/fetchApi/dataSources/windWaqi.ts | 2 +- App/util/theme.ts | 2 +- 9 files changed, 23 insertions(+), 24 deletions(-) diff --git a/App/Screens/ErrorScreen/ErrorScreen.tsx b/App/Screens/ErrorScreen/ErrorScreen.tsx index ac1c93ec..1b2b452b 100644 --- a/App/Screens/ErrorScreen/ErrorScreen.tsx +++ b/App/Screens/ErrorScreen/ErrorScreen.tsx @@ -15,7 +15,7 @@ // along with Sh**t! I Smoke. If not, see . 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'; @@ -41,13 +41,13 @@ export function ErrorScreen (props: ErrorScreenProps) { {i18n.t('error_screen_error_cannot_load_cigarettes')} - props.navigation.navigate('Search')}> - - - - + {i18n.t('error_screen_error_description')} {i18n.t('error_screen_error_message', { errorText: error })} diff --git a/App/Screens/Search/GpsItem/GpsItem.tsx b/App/Screens/Search/GpsItem/GpsItem.tsx index 13290178..2c18c04f 100644 --- a/App/Screens/Search/GpsItem/GpsItem.tsx +++ b/App/Screens/Search/GpsItem/GpsItem.tsx @@ -26,6 +26,10 @@ export function GpsItem () { const { setCurrentLocation } = useContext(CurrentLocationContext); const gps = useContext(GpsLocationContext); + if (!gps) { + return null; + } + const handleClick = () => { setCurrentLocation(gps); }; @@ -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} /> ); } diff --git a/App/Screens/Search/Search.tsx b/App/Screens/Search/Search.tsx index 0fbf30bb..7d4af11d 100644 --- a/App/Screens/Search/Search.tsx +++ b/App/Screens/Search/Search.tsx @@ -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'; @@ -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( @@ -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 }) { diff --git a/App/components/BoxButton/BoxButton.tsx b/App/components/BoxButton/BoxButton.tsx index f5c44f3b..c10014b9 100644 --- a/App/components/BoxButton/BoxButton.tsx +++ b/App/components/BoxButton/BoxButton.tsx @@ -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, diff --git a/App/components/Button/Button.tsx b/App/components/Button/Button.tsx index 6e7e0001..ef26b9bf 100644 --- a/App/components/Button/Button.tsx +++ b/App/components/Button/Button.tsx @@ -33,7 +33,7 @@ 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 ( diff --git a/App/stores/api.tsx b/App/stores/api.tsx index c04cc008..d6162781 100644 --- a/App/stores/api.tsx +++ b/App/stores/api.tsx @@ -45,6 +45,7 @@ export function ApiContextProvider ({ children }: ApiContextProviderProps) { useEffect(() => { setApi(undefined); + setError(undefined); if (!currentLocation) { return; diff --git a/App/stores/fetchApi/dataSources/aqicn.ts b/App/stores/fetchApi/dataSources/aqicn.ts index a689c3db..5c9676bd 100644 --- a/App/stores/fetchApi/dataSources/aqicn.ts +++ b/App/stores/fetchApi/dataSources/aqicn.ts @@ -26,7 +26,7 @@ import { pm25ToCigarettes } from './pm25ToCigarettes'; */ export async function aqicn ({ latitude, longitude }: LatLng) { const { data: response } = await axios.get( - `http://api.waqi.info/feed/geo:${latitude};${longitude}/?token=${ + `http://api.waqi.info/feed2/geo:${latitude};${longitude}/?token=${ Constants.manifest.extra.waqiToken }`, { timeout: 6000 } diff --git a/App/stores/fetchApi/dataSources/windWaqi.ts b/App/stores/fetchApi/dataSources/windWaqi.ts index b79812ff..a305d16c 100644 --- a/App/stores/fetchApi/dataSources/windWaqi.ts +++ b/App/stores/fetchApi/dataSources/windWaqi.ts @@ -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 } ); diff --git a/App/util/theme.ts b/App/util/theme.ts index b972a13d..092a04ab 100644 --- a/App/util/theme.ts +++ b/App/util/theme.ts @@ -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) From 7fa99bac22e054a295735c535102d0ede06dd638 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Mon, 22 Jul 2019 20:03:49 +0200 Subject: [PATCH 2/2] Revert data sources changes --- App/stores/fetchApi/dataSources/aqicn.ts | 2 +- App/stores/fetchApi/dataSources/windWaqi.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/App/stores/fetchApi/dataSources/aqicn.ts b/App/stores/fetchApi/dataSources/aqicn.ts index 5c9676bd..a689c3db 100644 --- a/App/stores/fetchApi/dataSources/aqicn.ts +++ b/App/stores/fetchApi/dataSources/aqicn.ts @@ -26,7 +26,7 @@ import { pm25ToCigarettes } from './pm25ToCigarettes'; */ export async function aqicn ({ latitude, longitude }: LatLng) { const { data: response } = await axios.get( - `http://api.waqi.info/feed2/geo:${latitude};${longitude}/?token=${ + `http://api.waqi.info/feed/geo:${latitude};${longitude}/?token=${ Constants.manifest.extra.waqiToken }`, { timeout: 6000 } diff --git a/App/stores/fetchApi/dataSources/windWaqi.ts b/App/stores/fetchApi/dataSources/windWaqi.ts index a305d16c..b79812ff 100644 --- a/App/stores/fetchApi/dataSources/windWaqi.ts +++ b/App/stores/fetchApi/dataSources/windWaqi.ts @@ -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/ma2pq/nearest?geo=1/${latitude}/${longitude}`, + `https://wind.waqi.info/mapq/nearest?geo=1/${latitude}/${longitude}`, { timeout: 6000 } );