2017-04-01 20:53:37 -05:00
|
|
|
// @flow
|
2018-01-27 16:56:01 -06:00
|
|
|
import React from 'react';
|
|
|
|
|
import { Button, Image, Text, View } from 'react-native';
|
2017-04-01 20:53:37 -05:00
|
|
|
import theme from '../ui-theme';
|
2017-07-02 12:32:26 -05:00
|
|
|
import { StrongText, SubText } from '../components/ItemTile';
|
2017-11-26 19:52:16 -06:00
|
|
|
import typeof FoodItemRecord from '../records/FoodItemRecord';
|
|
|
|
|
import { type Quantity } from '../constants/QuantityConstants';
|
2017-06-03 19:43:45 -05:00
|
|
|
import typeof PlaceRecord from '../records/PlaceRecord';
|
2018-01-27 16:56:01 -06:00
|
|
|
import { compose, withState, withHandlers, onlyUpdateForKeys, withProps } from 'recompose';
|
2017-04-14 12:28:48 -05:00
|
|
|
import IconButton from '../components/IconButton';
|
2017-04-15 15:11:22 -05:00
|
|
|
import { withFoodItem } from '../enhancers/foodItemEnhancers';
|
2017-04-26 22:06:31 -05:00
|
|
|
import { withPlaceForFoodItem } from '../enhancers/placeEnhancers';
|
2017-04-20 16:28:13 -05:00
|
|
|
import Carousel from 'react-native-looped-carousel';
|
2017-04-23 20:15:46 -05:00
|
|
|
import CountBadge from '../components/CountBadge';
|
2017-08-06 11:33:41 -05:00
|
|
|
import { routeWithTitle } from '../helpers/RouteHelpers';
|
|
|
|
|
import { Link } from 'react-router-native';
|
2017-11-19 12:46:39 -06:00
|
|
|
import moment from 'moment';
|
2017-11-26 19:52:16 -06:00
|
|
|
import { withUpdateQuantity } from '../enhancers/quantityEnhancers';
|
2018-01-27 16:56:01 -06:00
|
|
|
import { getQuantityLabelText } from '../helpers/QuantityHelpers';
|
|
|
|
|
import AuthManager from '../AuthManager';
|
|
|
|
|
import RouterButton from 'react-router-native-button';
|
|
|
|
|
import QuantityModal from '../modals/QuantityModal';
|
2017-04-14 12:28:48 -05:00
|
|
|
|
2017-04-23 20:15:46 -05:00
|
|
|
const { foodItemDetails: style } = theme;
|
2017-04-01 20:53:37 -05:00
|
|
|
|
2017-04-23 20:15:46 -05:00
|
|
|
const stretchedStyle = { position: 'absolute', top: 0, left: 0, right: 0, bottom: 0 };
|
|
|
|
|
|
|
|
|
|
const contentTileStyle = {
|
|
|
|
|
backgroundColor: 'white',
|
2017-11-19 12:46:39 -06:00
|
|
|
padding: 15,
|
|
|
|
|
marginBottom: 10,
|
2017-04-23 20:15:46 -05:00
|
|
|
};
|
2017-04-20 16:28:13 -05:00
|
|
|
|
2018-01-27 16:56:01 -06:00
|
|
|
type Props = {
|
|
|
|
|
foodItem: FoodItemRecord,
|
|
|
|
|
place: PlaceRecord,
|
|
|
|
|
currentImage: number,
|
|
|
|
|
quantityModalOpen: boolean,
|
|
|
|
|
isLoggedIn: boolean,
|
|
|
|
|
changeCurrentImage: (index: number) => void,
|
|
|
|
|
updateAmount: (quantity: Quantity) => void,
|
|
|
|
|
updateQuantity: (arg: { foodItemId: string, quantity: Quantity }) => void,
|
|
|
|
|
toggleQuantityModal: () => void,
|
|
|
|
|
addPhoto: () => void,
|
|
|
|
|
};
|
2017-07-23 19:58:10 -05:00
|
|
|
|
2018-01-27 16:56:01 -06:00
|
|
|
export const FoodItemDetail = (props: Props) => {
|
|
|
|
|
const {
|
|
|
|
|
foodItem,
|
|
|
|
|
place,
|
|
|
|
|
currentImage,
|
|
|
|
|
changeCurrentImage,
|
|
|
|
|
isLoggedIn,
|
|
|
|
|
addPhoto,
|
|
|
|
|
toggleQuantityModal,
|
|
|
|
|
quantityModalOpen,
|
|
|
|
|
updateAmount,
|
|
|
|
|
} = props;
|
|
|
|
|
|
|
|
|
|
if (!foodItem || !place) {
|
|
|
|
|
return <View />;
|
|
|
|
|
}
|
2017-04-20 16:28:13 -05:00
|
|
|
|
2018-01-27 16:56:01 -06:00
|
|
|
const visibleImages = foodItem.images.filter(image => !!image);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<View style={{ ...theme.page.container }}>
|
|
|
|
|
<View style={{ flex: 3 }}>
|
|
|
|
|
{visibleImages.size === 1 && (
|
|
|
|
|
<Image style={stretchedStyle} source={{ uri: visibleImages.get(0) }} />
|
|
|
|
|
)}
|
|
|
|
|
{visibleImages.size > 1 && (
|
|
|
|
|
<Carousel autoplay={false} onAnimateNextPage={changeCurrentImage} style={stretchedStyle}>
|
|
|
|
|
{visibleImages.map(uri => (
|
|
|
|
|
<Image key={uri} style={{ flex: 1, resizeMode: 'stretch' }} source={{ uri }} />
|
|
|
|
|
))}
|
|
|
|
|
</Carousel>
|
|
|
|
|
)}
|
|
|
|
|
<CountBadge currentImage={currentImage + 1} totalCount={visibleImages.size} />
|
|
|
|
|
</View>
|
|
|
|
|
<View style={{ ...contentTileStyle }}>
|
|
|
|
|
<Link
|
|
|
|
|
to={routeWithTitle(`/place/${place.id || ''}`, place.name)}
|
|
|
|
|
underlayColor={theme.itemTile.pressHighlightColor}>
|
|
|
|
|
<View>
|
|
|
|
|
<StrongText>{place.name}</StrongText>
|
|
|
|
|
<SubText>{place.address}</SubText>
|
|
|
|
|
</View>
|
|
|
|
|
</Link>
|
|
|
|
|
</View>
|
|
|
|
|
<View
|
|
|
|
|
style={{
|
|
|
|
|
flexBasis: 100,
|
|
|
|
|
flexGrow: 1,
|
|
|
|
|
...contentTileStyle,
|
|
|
|
|
flexDirection: 'column',
|
|
|
|
|
justifyContent: 'space-between',
|
|
|
|
|
}}>
|
|
|
|
|
<Text style={{ fontSize: 42, color: 'black' }}>
|
|
|
|
|
{getQuantityLabelText(foodItem.quantity)}
|
|
|
|
|
</Text>
|
|
|
|
|
<SubText>
|
|
|
|
|
Last updated at {moment(foodItem.lastupdated).format('h:mm A on MMM D, YYYY')}
|
|
|
|
|
</SubText>
|
|
|
|
|
{isLoggedIn && (
|
|
|
|
|
<Button
|
|
|
|
|
title="Update quantity"
|
|
|
|
|
onPress={toggleQuantityModal}
|
|
|
|
|
color={theme.palette.primaryColor}
|
2017-04-23 20:15:46 -05:00
|
|
|
/>
|
2018-01-27 16:56:01 -06:00
|
|
|
)}
|
|
|
|
|
{!isLoggedIn && (
|
|
|
|
|
<RouterButton
|
|
|
|
|
title="Log in to update quantity"
|
|
|
|
|
to={`/login?returnto=/foodItem/${foodItem.id}`}
|
|
|
|
|
color={theme.palette.primaryColor}
|
2017-04-23 20:15:46 -05:00
|
|
|
/>
|
2018-01-27 16:56:01 -06:00
|
|
|
)}
|
2017-04-20 06:32:13 -05:00
|
|
|
</View>
|
2018-01-27 16:56:01 -06:00
|
|
|
<View style={{ flex: 1, ...contentTileStyle }}>
|
|
|
|
|
{/* <IconButton
|
|
|
|
|
glyph="stars"
|
|
|
|
|
text="Add to Faves"
|
|
|
|
|
onPress={this.addToFaves}
|
|
|
|
|
color={style.actionIconColor}
|
|
|
|
|
/> */}
|
|
|
|
|
<IconButton
|
|
|
|
|
glyph="insert-photo"
|
|
|
|
|
text="Add Photo"
|
|
|
|
|
onPress={addPhoto}
|
|
|
|
|
color={style.actionIconColor}
|
|
|
|
|
/>
|
|
|
|
|
</View>
|
|
|
|
|
<QuantityModal
|
|
|
|
|
isVisible={quantityModalOpen}
|
|
|
|
|
quantity={foodItem.quantity}
|
|
|
|
|
onChange={updateAmount}
|
|
|
|
|
onClose={toggleQuantityModal}
|
|
|
|
|
/>
|
|
|
|
|
</View>
|
|
|
|
|
);
|
|
|
|
|
};
|
2017-04-01 20:53:37 -05:00
|
|
|
|
2018-01-27 16:56:01 -06:00
|
|
|
export default compose(
|
|
|
|
|
withFoodItem,
|
|
|
|
|
withPlaceForFoodItem,
|
|
|
|
|
withUpdateQuantity,
|
|
|
|
|
withProps(() => ({
|
|
|
|
|
isLoggedIn: AuthManager.isLoggedIn(),
|
|
|
|
|
})),
|
|
|
|
|
withState('currentImage', 'changeCurrentImage', 0),
|
|
|
|
|
withState('quantityModalOpen', 'setQuantityModalOpen', false),
|
|
|
|
|
withHandlers({
|
|
|
|
|
addPhoto: () => () => {},
|
|
|
|
|
updateAmount: ({ updateQuantity, foodItem }: Props) => (quantity: Quantity) => {
|
|
|
|
|
updateQuantity({ foodItemId: foodItem.id, quantity });
|
|
|
|
|
},
|
|
|
|
|
toggleQuantityModal: ({ quantityModalOpen, setQuantityModalOpen }) => () => {
|
|
|
|
|
setQuantityModalOpen(!quantityModalOpen);
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
onlyUpdateForKeys(['foodItem', 'place', 'currentImage', 'quantityModalOpen'])
|
|
|
|
|
)(FoodItemDetail);
|