2017-03-05 18:09:01 -06:00
|
|
|
// @flow
|
2017-05-13 22:33:56 -05:00
|
|
|
import React, { Component, PropTypes } from 'react';
|
2017-03-27 20:48:31 -05:00
|
|
|
import { View, ScrollView } from 'react-native';
|
2017-03-05 18:09:01 -06:00
|
|
|
import theme from '../ui-theme';
|
2017-07-23 19:58:10 -05:00
|
|
|
import FoodItemTile from '../components/FoodItemTile';
|
2017-05-13 22:33:56 -05:00
|
|
|
import { ActionButton } from 'react-native-material-ui';
|
|
|
|
|
import { routeWithTitle } from '../helpers/RouteHelpers';
|
2017-05-21 20:25:19 -05:00
|
|
|
import FoodItemList from '../components/FoodItemList';
|
|
|
|
|
import { type FoodItem } from '../records/FoodItemRecord';
|
|
|
|
|
import { withPlaceForFoodItem } from '../enhancers/placeEnhancers';
|
2017-05-13 22:33:56 -05:00
|
|
|
|
|
|
|
|
const { shape, func } = PropTypes;
|
2017-03-05 18:09:01 -06:00
|
|
|
|
2017-05-21 20:25:19 -05:00
|
|
|
const FoodItemWithPlace = withPlaceForFoodItem(FoodItemTile);
|
|
|
|
|
|
|
|
|
|
const renderFoodItem = (foodItem: FoodItem) => <FoodItemWithPlace key={foodItem.id} foodItem={foodItem} />;
|
2017-03-25 21:05:55 -05:00
|
|
|
|
|
|
|
|
class Food extends Component {
|
2017-05-13 22:33:56 -05:00
|
|
|
static displayName = 'Food';
|
|
|
|
|
static contextTypes = {
|
|
|
|
|
router: shape({
|
|
|
|
|
history: shape({
|
|
|
|
|
push: func.isRequired,
|
|
|
|
|
}).isRequired,
|
|
|
|
|
}).isRequired,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
addFoodItem = () => {
|
|
|
|
|
const newRoute = routeWithTitle('/createFoodItem', 'Add a Food Item');
|
|
|
|
|
this.context.router.history.push(newRoute);
|
|
|
|
|
};
|
2017-03-05 18:09:01 -06:00
|
|
|
|
2017-05-13 22:33:56 -05:00
|
|
|
render() {
|
|
|
|
|
return (
|
|
|
|
|
<View style={theme.page.container}>
|
|
|
|
|
<ScrollView>
|
2017-05-21 20:25:19 -05:00
|
|
|
<FoodItemList renderFoodItem={renderFoodItem} />
|
2017-05-13 22:33:56 -05:00
|
|
|
</ScrollView>
|
|
|
|
|
<ActionButton icon="add" onPress={this.addFoodItem} />
|
|
|
|
|
</View>
|
|
|
|
|
);
|
|
|
|
|
}
|
2017-03-05 18:09:01 -06:00
|
|
|
}
|
2017-03-25 21:05:55 -05:00
|
|
|
|
|
|
|
|
export default Food;
|