// @flow
import React, { Component } from 'react';
import { Image, View } from 'react-native';
import theme from '../ui-theme';
import { StrongText, SubText } from '../components/ItemTile';
import typeof FoodItemRecord from '../records/FoodItemRecord';
import { type Quantity } from '../constants/QuantityConstants';
import typeof PlaceRecord from '../records/PlaceRecord';
import { compose, pure } from 'recompose';
import IconButton from '../components/IconButton';
import { withFoodItem } from '../enhancers/foodItemEnhancers';
import { withPlaceForFoodItem } from '../enhancers/placeEnhancers';
import Carousel from 'react-native-looped-carousel';
import CountBadge from '../components/CountBadge';
import QuantityPicker from '../components/QuantityPicker';
import { routeWithTitle } from '../helpers/RouteHelpers';
import { Link } from 'react-router-native';
import moment from 'moment';
import { withUpdateQuantity } from '../enhancers/quantityEnhancers';
const { foodItemDetails: style } = theme;
const stretchedStyle = { position: 'absolute', top: 0, left: 0, right: 0, bottom: 0 };
const contentTileStyle = {
backgroundColor: 'white',
padding: 15,
marginBottom: 10,
};
export class FoodItemDetail extends Component {
static displayName = 'FoodItemDetail';
props: {
foodItem: FoodItemRecord,
place: PlaceRecord,
updateQuantity: ({ foodItemId: string, quantity: Quantity }) => void,
};
state: {
isFavorite: boolean,
currentImage: number,
};
state = {
currentImage: 0,
};
// TODO placeholder implementation until we get a backend
addToFaves = () =>
this.setState(prevState => ({
isFavorite: !prevState.isFavorite,
}));
updateAmount = (quantity: Quantity) => {
const { updateQuantity, foodItem: { id: foodItemId } } = this.props;
updateQuantity({ foodItemId, quantity });
};
// TODO
addPhoto = () => {};
changeCurrentImage = (currentImage: number) => this.setState({ currentImage });
render() {
const { foodItem, place } = this.props;
if (!foodItem || !place) {
return ;
}
const { images, quantity } = foodItem;
const viewableImages = images.filter(image => !!image);
return (
{viewableImages.size === 1 && (
)}
{viewableImages.size > 1 && (
{viewableImages.map(uri => (
))}
)}
{place.name}
{place.address}
Last updated at {moment(foodItem.lastupdated).format('h:mm A on MMM D, YYYY')}
);
}
}
const enhance = compose(pure, withFoodItem, withPlaceForFoodItem, withUpdateQuantity);
export default enhance(FoodItemDetail);