Skip to content

Commit

Permalink
fix: Small tweaks, including fix ErrorScreen (#142)
Browse files Browse the repository at this point in the history
* fix: Fix error screen not being able to move to search

* Revert data sources changes
  • Loading branch information
amaury1093 committed Jul 23, 2019
1 parent 22604e4 commit 658a6fa
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 22 deletions.
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/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

0 comments on commit 658a6fa

Please sign in to comment.