aretherecookies-mobile/js/pages/FoodItemDetail.js

126 lines
3.3 KiB
JavaScript
Raw Normal View History

2017-04-01 20:53:37 -05:00
// @flow
import React, { Component } from 'react';
2017-04-23 20:15:46 -05:00
import { Image, View } from 'react-native';
2017-04-01 20:53:37 -05:00
import theme from '../ui-theme';
import { StrongText, SubText } from '../components/ItemTile';
2017-06-04 11:37:38 -05:00
import { type FoodItem, type Quantity, QUANTITY_MANY } from '../records/FoodItemRecord';
2017-06-03 19:43:45 -05:00
import typeof PlaceRecord from '../records/PlaceRecord';
import { compose, pure } from 'recompose';
2017-04-14 12:28:48 -05:00
import IconButton from '../components/IconButton';
import { withFoodItem } from '../enhancers/foodItemEnhancers';
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';
import QuantityPicker from '../components/QuantityPicker';
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',
paddingLeft: 20,
paddingRight: 20,
};
2017-04-20 16:28:13 -05:00
2017-04-01 20:53:37 -05:00
export class FoodItemDetail extends Component {
2017-04-20 06:32:13 -05:00
static displayName = 'FoodItemDetail';
2017-04-01 20:53:37 -05:00
2017-04-20 06:32:13 -05:00
props: {
foodItem: FoodItem,
2017-06-03 19:43:45 -05:00
place: PlaceRecord,
2017-04-20 06:32:13 -05:00
};
2017-04-01 20:53:37 -05:00
2017-04-20 06:32:13 -05:00
state: {
2017-04-20 16:28:13 -05:00
isFavorite: boolean,
2017-06-03 19:43:45 -05:00
quantity: Quantity,
2017-04-20 16:28:13 -05:00
currentImage: number,
2017-04-20 06:32:13 -05:00
};
2017-04-14 21:47:54 -05:00
2017-04-20 16:28:13 -05:00
state = {
currentImage: 0,
2017-06-04 11:37:38 -05:00
quantity: QUANTITY_MANY,
2017-04-20 16:28:13 -05:00
};
2017-04-14 21:47:54 -05:00
2017-04-23 20:15:46 -05:00
// TODO placeholder implementation until we get a backend
2017-04-20 16:28:13 -05:00
addToFaves = () =>
this.setState(prevState => ({
isFavorite: !prevState.isFavorite,
}));
2017-04-14 21:47:54 -05:00
2017-06-03 19:43:45 -05:00
updateAmount = (quantity: Quantity) => this.setState({ quantity });
2017-04-14 21:47:54 -05:00
2017-04-23 20:15:46 -05:00
// TODO
2017-04-20 06:32:13 -05:00
addPhoto = () => {};
2017-04-14 21:47:54 -05:00
2017-06-03 19:43:45 -05:00
changeCurrentImage = (currentImage: number) => this.setState({ currentImage });
2017-04-14 21:47:54 -05:00
2017-04-20 06:32:13 -05:00
render() {
const { foodItem, place } = this.props;
2017-07-23 19:58:10 -05:00
if (!foodItem || !place) {
return <View />;
}
2017-04-20 16:28:13 -05:00
const { images, quantity } = foodItem;
const viewableImages = images.filter(image => !!image);
2017-04-20 06:32:13 -05:00
return (
2017-04-20 16:28:13 -05:00
<View style={{ ...theme.page.container }}>
2017-04-20 08:32:57 -05:00
<View style={{ flex: 3 }}>
2017-04-20 16:28:13 -05:00
{viewableImages.length === 1 &&
2017-04-23 20:15:46 -05:00
<Image style={stretchedStyle} source={{ uri: viewableImages[0] }} />}
2017-04-20 16:28:13 -05:00
{viewableImages.length > 1 &&
2017-04-23 20:15:46 -05:00
<Carousel autoplay={false} onAnimateNextPage={this.changeCurrentImage} style={stretchedStyle}>
2017-06-11 18:32:21 -05:00
{viewableImages.map(uri =>
2017-04-20 16:28:13 -05:00
<Image key={uri} style={{ flex: 1, resizeMode: 'stretch' }} source={{ uri }} />
2017-06-11 18:32:21 -05:00
)}
2017-04-20 16:28:13 -05:00
</Carousel>}
2017-04-23 20:15:46 -05:00
<CountBadge currentImage={this.state.currentImage + 1} totalCount={viewableImages.length} />
2017-04-20 06:32:13 -05:00
</View>
2017-04-23 20:15:46 -05:00
<View style={{ flex: 1, marginBottom: 10, ...contentTileStyle }}>
<View style={{ marginTop: 15 }}>
<StrongText>
{place.name}
</StrongText>
<SubText>
{place.address}
</SubText>
</View>
2017-04-20 06:32:13 -05:00
</View>
2017-04-20 08:32:57 -05:00
<View
style={{
flex: 1,
marginBottom: 10,
2017-04-23 20:15:46 -05:00
...contentTileStyle,
2017-04-20 08:32:57 -05:00
}}
>
2017-06-11 18:32:21 -05:00
<QuantityPicker
quantity={this.state.quantity || quantity}
onValueChange={this.updateAmount}
style={{ flex: 1 }}
/>
2017-04-20 08:32:57 -05:00
</View>
2017-04-23 20:15:46 -05:00
<View style={{ flex: 2, ...contentTileStyle }}>
<IconButton
glyph="stars"
text="Add to Faves"
onPress={this.addToFaves}
color={style.actionIconColor}
/>
<IconButton
glyph="insert-photo"
text="Add Photo"
onPress={this.addPhoto}
color={style.actionIconColor}
/>
2017-04-20 08:32:57 -05:00
</View>
2017-04-20 06:32:13 -05:00
</View>
);
}
2017-04-01 20:53:37 -05:00
}
const enhance = compose(pure, withFoodItem, withPlaceForFoodItem);
2017-04-01 20:53:37 -05:00
export default enhance(FoodItemDetail);