fix crash on PlaceDetails when foodItems is null

This commit is contained in:
Bart Akeley 2018-05-06 09:53:44 -05:00
parent c93064515a
commit e4c44e9aff
2 changed files with 31 additions and 15 deletions

View file

@ -5,6 +5,7 @@ import compose from 'recompose/compose';
import Places$ from '../streams/PlacesStream';
import FoodItems$ from '../streams/FoodItemsStream';
import { path } from 'ramda';
import { List } from 'immutable';
export const withPlaces = mapPropsStream(props$ =>
props$.combineLatest(Places$, (props, places) => {
@ -43,11 +44,14 @@ export const withPlaceForFoodItem = mapPropsStream(props$ =>
);
export const withFoodItemsForPlace = mapPropsStream(props$ =>
props$.combineLatest(FoodItems$, (props, foodItems) => {
props$.combineLatest(FoodItems$, (props, foodItemsMap) => {
const placeId = props.placeId;
const foodItems = foodItemsMap
? foodItemsMap.toList().filter(foodItem => placeId === foodItem.placeId)
: List();
return {
...props,
foodItems: foodItems.toList().filter(foodItem => placeId === foodItem.placeId),
foodItems,
};
})
);

View file

@ -4,7 +4,11 @@ import { View, Image, ScrollView } from 'react-native';
import theme from '../ui-theme';
import { compose, pure } from 'recompose';
import typeof PlaceRecord from '../records/PlaceRecord';
import { withPlace, withPlaceIdFromRoute, withFoodItemsForPlace } from '../enhancers/placeEnhancers';
import {
withPlace,
withPlaceIdFromRoute,
withFoodItemsForPlace,
} from '../enhancers/placeEnhancers';
import Carousel from 'react-native-looped-carousel';
import CountBadge from '../components/CountBadge';
import { StrongText } from '../components/ItemTile';
@ -65,24 +69,31 @@ export class PlaceDetail extends Component {
<ScrollView style={theme.page.container}>
<View style={{ height: 200 }}>
{photos.size === 1 && <Image style={stretchedStyle} source={{ uri: photos.first() }} />}
{photos.size > 1 &&
<Carousel autoplay={false} onAnimateNextPage={this.changeCurrentImage} style={stretchedStyle}>
{photos.map(uri =>
{photos.size > 1 && (
<Carousel
autoplay={false}
onAnimateNextPage={this.changeCurrentImage}
style={stretchedStyle}>
{photos.map(uri => (
<Image key={uri} style={{ flex: 1, resizeMode: 'stretch' }} source={{ uri }} />
)}
</Carousel>}
))}
</Carousel>
)}
<CountBadge currentImage={currentImage + 1} totalCount={photos.size} />
</View>
<View style={{ height: 50, marginBottom: 10, ...contentTileStyle }}>
<View style={{ marginTop: 15 }}>
<StrongText>
{place.address}
</StrongText>
<StrongText>{place.address}</StrongText>
</View>
</View>
<View
style={{ flexBasis: 75, ...contentTileStyle, marginBottom: 10, paddingTop: 5, paddingBottom: 10 }}
>
style={{
flexBasis: 75,
...contentTileStyle,
marginBottom: 10,
paddingTop: 5,
paddingBottom: 10,
}}>
<IconButton
glyph="stars"
text="Add to Faves"
@ -99,8 +110,9 @@ export class PlaceDetail extends Component {
<View style={{ flex: 2, ...contentTileStyle, paddingTop: 10 }}>
<StrongText>Products</StrongText>
{!!foodItems &&
foodItems.size &&
foodItems.map(foodItem => <FoodItemTile key={foodItem.id} foodItem={foodItem} place={place} />)}
foodItems.map(foodItem => (
<FoodItemTile key={foodItem.id} foodItem={foodItem} place={place} />
))}
</View>
</ScrollView>
);