From e4c44e9affc2f6bf0dfbcbd11eda5650a5d3a71a Mon Sep 17 00:00:00 2001 From: Bart Akeley Date: Sun, 6 May 2018 09:53:44 -0500 Subject: [PATCH] fix crash on PlaceDetails when foodItems is null --- js/enhancers/placeEnhancers.js | 8 +++++-- js/pages/PlaceDetail.js | 38 ++++++++++++++++++++++------------ 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/js/enhancers/placeEnhancers.js b/js/enhancers/placeEnhancers.js index b3b16bc..a22fce9 100644 --- a/js/enhancers/placeEnhancers.js +++ b/js/enhancers/placeEnhancers.js @@ -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, }; }) ); diff --git a/js/pages/PlaceDetail.js b/js/pages/PlaceDetail.js index 9992bfe..26a0e60 100644 --- a/js/pages/PlaceDetail.js +++ b/js/pages/PlaceDetail.js @@ -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 { {photos.size === 1 && } - {photos.size > 1 && - - {photos.map(uri => + {photos.size > 1 && ( + + {photos.map(uri => ( - )} - } + ))} + + )} - - {place.address} - + {place.address} + style={{ + flexBasis: 75, + ...contentTileStyle, + marginBottom: 10, + paddingTop: 5, + paddingBottom: 10, + }}> Products {!!foodItems && - foodItems.size && - foodItems.map(foodItem => )} + foodItems.map(foodItem => ( + + ))} );