2017-04-01 20:53:37 -05:00
|
|
|
// @flow
|
|
|
|
|
import React, { Component } from 'react';
|
2017-07-23 19:58:10 -05:00
|
|
|
import { View, Image, ScrollView } from 'react-native';
|
2017-04-01 20:53:37 -05:00
|
|
|
import theme from '../ui-theme';
|
2017-04-09 23:28:28 -05:00
|
|
|
import { compose, pure } from 'recompose';
|
2017-07-23 19:58:10 -05:00
|
|
|
import typeof PlaceRecord from '../records/PlaceRecord';
|
|
|
|
|
import { withPlace, withPlaceIdFromRoute, withFoodItemsForPlace } from '../enhancers/placeEnhancers';
|
|
|
|
|
import Carousel from 'react-native-looped-carousel';
|
|
|
|
|
import CountBadge from '../components/CountBadge';
|
|
|
|
|
import { StrongText } from '../components/ItemTile';
|
|
|
|
|
import IconButton from '../components/IconButton';
|
|
|
|
|
import { type List } from 'immutable';
|
|
|
|
|
import typeof FoodItemRecord from '../records/FoodItemRecord';
|
|
|
|
|
import FoodItemTile from '../components/FoodItemTile';
|
|
|
|
|
|
|
|
|
|
const { placeDetails: style } = theme;
|
|
|
|
|
|
|
|
|
|
const stretchedStyle = { position: 'absolute', top: 0, left: 0, right: 0, bottom: 0 };
|
|
|
|
|
|
|
|
|
|
const contentTileStyle = {
|
|
|
|
|
backgroundColor: 'white',
|
|
|
|
|
paddingLeft: 20,
|
|
|
|
|
paddingRight: 20,
|
|
|
|
|
};
|
2017-04-01 20:53:37 -05:00
|
|
|
|
|
|
|
|
export class PlaceDetail extends Component {
|
2017-06-03 19:43:45 -05:00
|
|
|
static displayName = 'PlaceDetail';
|
2017-04-01 20:53:37 -05:00
|
|
|
|
2017-06-03 19:43:45 -05:00
|
|
|
props: {
|
2017-07-23 19:58:10 -05:00
|
|
|
place: ?PlaceRecord,
|
|
|
|
|
foodItems: ?List<FoodItemRecord>,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
state: {
|
|
|
|
|
currentImage: number,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
state = {
|
|
|
|
|
currentImage: 0,
|
2017-06-03 19:43:45 -05:00
|
|
|
};
|
2017-04-01 20:53:37 -05:00
|
|
|
|
2017-07-23 19:58:10 -05:00
|
|
|
changeCurrentImage = (currentImage: number) => this.setState({ currentImage });
|
|
|
|
|
|
|
|
|
|
// TODO placeholder implementation until we get a backend
|
|
|
|
|
addToFaves = () =>
|
|
|
|
|
this.setState(prevState => ({
|
|
|
|
|
isFavorite: !prevState.isFavorite,
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
// todo - build a map view and open it here
|
|
|
|
|
viewOnMap = () => {};
|
|
|
|
|
|
2017-06-03 19:43:45 -05:00
|
|
|
// todo: need to get the item from the stream by this id
|
|
|
|
|
render() {
|
2017-07-23 19:58:10 -05:00
|
|
|
const { place, foodItems } = this.props;
|
|
|
|
|
|
|
|
|
|
if (!place) {
|
|
|
|
|
return <View />;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const { photos } = place;
|
|
|
|
|
const { currentImage } = this.state;
|
|
|
|
|
|
2017-06-03 19:43:45 -05:00
|
|
|
return (
|
2017-07-23 19:58:10 -05:00
|
|
|
<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 =>
|
|
|
|
|
<Image key={uri} style={{ flex: 1, resizeMode: 'stretch' }} source={{ uri }} />
|
|
|
|
|
)}
|
|
|
|
|
</Carousel>}
|
|
|
|
|
<CountBadge currentImage={currentImage + 1} totalCount={photos.size} />
|
|
|
|
|
</View>
|
|
|
|
|
<View style={{ height: 50, marginBottom: 10, ...contentTileStyle }}>
|
|
|
|
|
<View style={{ marginTop: 15 }}>
|
|
|
|
|
<StrongText>
|
|
|
|
|
{place.address}
|
|
|
|
|
</StrongText>
|
|
|
|
|
</View>
|
|
|
|
|
</View>
|
|
|
|
|
<View
|
|
|
|
|
style={{ flexBasis: 75, ...contentTileStyle, marginBottom: 10, paddingTop: 5, paddingBottom: 10 }}
|
|
|
|
|
>
|
|
|
|
|
<IconButton
|
|
|
|
|
glyph="stars"
|
|
|
|
|
text="Add to Faves"
|
|
|
|
|
onPress={this.addToFaves}
|
|
|
|
|
color={style.actionIconColor}
|
|
|
|
|
/>
|
|
|
|
|
<IconButton
|
|
|
|
|
glyph="map"
|
|
|
|
|
text="View on a Map"
|
|
|
|
|
onPress={this.viewOnMap}
|
|
|
|
|
color={style.actionIconColor}
|
|
|
|
|
/>
|
|
|
|
|
</View>
|
|
|
|
|
<View style={{ flex: 2, ...contentTileStyle, paddingTop: 10 }}>
|
|
|
|
|
<StrongText>Products</StrongText>
|
|
|
|
|
{!!foodItems &&
|
|
|
|
|
foodItems.size &&
|
|
|
|
|
foodItems.map(foodItem => <FoodItemTile key={foodItem.id} foodItem={foodItem} place={place} />)}
|
|
|
|
|
</View>
|
|
|
|
|
</ScrollView>
|
2017-06-03 19:43:45 -05:00
|
|
|
);
|
|
|
|
|
}
|
2017-04-01 20:53:37 -05:00
|
|
|
}
|
|
|
|
|
|
2017-07-23 19:58:10 -05:00
|
|
|
const enhance = compose(pure, withPlaceIdFromRoute, withPlace, withFoodItemsForPlace);
|
2017-04-01 20:53:37 -05:00
|
|
|
|
|
|
|
|
export default enhance(PlaceDetail);
|