Places list

This commit is contained in:
Bart Akeley 2017-03-26 19:38:29 -05:00
parent f2c6f36920
commit 5de8c74c8e
10 changed files with 110 additions and 25 deletions

View file

@ -2,7 +2,8 @@
import React from 'react';
import { Text, View } from 'react-native';
import { pure } from 'recompose';
import { type FoodItem } from '../records/FoodRecord';
import { type FoodItem } from '../records/FoodItemRecord';
import { type Place } from '../records/PlaceRecord';
import theme from '../ui-theme';
export const Thumbnail = ({ thumb }: { thumb: ?string }) => (
@ -32,7 +33,7 @@ export const AvailableCount = ({ count }: { count: number }) => (
</View>
);
export const PlaceTile = pure(({ place }: { place: Object }) => (
export const PlaceTile = pure(({ place }: { place: Place }) => (
<View style={{ height: 70, flexDirection: 'row' }}>
<Thumbnail thumb={place.thumb} />
<NameAndPlace name={place.name} place="Whole Foods" />

View file

@ -1,10 +1,9 @@
// @flow
import mapPropsStream from 'recompose/mapPropsStream';
import FoodItems$ from '../streams/FoodItems';
import { Observable } from 'rxjs';
import FoodItems$ from '../streams/FoodItemsStream';
export default mapPropsStream(props$ =>
Observable.combineLatest(props$, FoodItems$, (props, foodItems) => {
props$.combineLatest(FoodItems$, (props, foodItems) => {
return {
...props,
foodItems,

View file

@ -0,0 +1,11 @@
// @flow
import mapPropsStream from 'recompose/mapPropsStream';
import Places$ from '../streams/PlacesStream';
export default mapPropsStream(props$ =>
props$.combineLatest(Places$, (props, places) => {
return {
...props,
places,
};
}));

View file

@ -0,0 +1,4 @@
// @flow
import { type List } from 'immutable';
export const pushInto = <T>(list: List<T>, item: T): List<T> => list.push(item);

View file

@ -9,14 +9,11 @@ import { pure, compose } from 'recompose';
import { FoodItemTile } from '../components/ItemTile';
const enhance = compose(pure, enhanceWithFoodItems);
const FoodItemList = enhance(({ foodItems }) => {
return (
<View>
{foodItems.map((foodItem, index) => <FoodItemTile foodItem={foodItem} key={index} />)}
</View>
);
});
const FoodItemList = enhance(({ foodItems }) => (
<View>
{foodItems.map((foodItem, index) => <FoodItemTile foodItem={foodItem} key={index} />)}
</View>
));
class Food extends Component {
static displayName = 'Food';

View file

@ -1,25 +1,33 @@
// @flow
import React, { Component } from 'react';
import { Text, View } from 'react-native';
import { View } from 'react-native';
import theme from '../ui-theme';
import TopTabs from '../components/TopTabs';
import { PlaceTile } from '../components/ItemTile';
import { compose, pure } from 'recompose';
import enhanceWithPlaces from '../enhancers/enhanceWithPlaces';
type Props = {
route: Object,
navigator: Object,
};
const enhance = compose(pure, enhanceWithPlaces);
const PlacesList = enhance(({ places }) => (
<View>
{places.map((place, index) => <PlaceTile place={place} key={index} />)}
</View>
));
export default class Places extends Component {
static displayName = 'Places';
props: Props;
props: {
route: Object,
navigator: Object,
};
render() {
const { route, navigator } = this.props;
return (
<View style={theme.page.container}>
<TopTabs route={route} navigator={navigator} />
<Text>Places!</Text>
<PlacesList />
</View>
);
}

View file

@ -19,4 +19,4 @@ const FoodRecordDefaults: FoodItem = {
thumb: '',
};
export default Record(FoodRecordDefaults, 'FoodRecord');
export default Record(FoodRecordDefaults, 'FoodItemRecord');

20
js/records/PlaceRecord.js Normal file
View file

@ -0,0 +1,20 @@
// @flow
import { List, Record } from 'immutable';
export type Place = {
id: number,
name: string,
addess: string,
images: List<string>,
thumb: string,
};
const FoodRecordDefaults: Place = {
id: null,
name: '',
address: '',
images: List(),
thumb: '',
};
export default Record(FoodRecordDefaults, 'PlaceRecord');

View file

@ -1,7 +1,8 @@
//@flow
import FoodRecord from '../records/FoodRecord';
import FoodItemRecord from '../records/FoodItemRecord';
import { Observable } from 'rxjs';
import { List } from 'immutable';
import { pushInto } from '../helpers/ImmutableHelpers';
// TODO open a websoket and create observable from it
const DUMMY_DATA = [
@ -42,6 +43,4 @@ const DUMMY_DATA = [
},
];
const pushInto = (list, item) => list.push(item);
export default Observable.from(DUMMY_DATA).map(FoodRecord).scan(pushInto, List());
export default Observable.from(DUMMY_DATA).map(FoodItemRecord).scan(pushInto, List());

View file

@ -0,0 +1,46 @@
// @flow
import PlaceRecord from '../records/PlaceRecord';
import { Observable } from 'rxjs';
import { List } from 'immutable';
import { pushInto } from '../helpers/ImmutableHelpers';
// TODO open a websoket and create observable from it
const DUMMY_DATA = [
{
id: 1,
name: 'Whole Foods',
address: '525 N. Lamar Blvd, Austin',
},
{
id: 2,
name: "Trader Joe's",
addresss: '211 Walter Seaholm Dr, Ste 100, Austin',
},
{
id: 3,
name: 'Royal Blue Grocery',
address: '525 N. Lamar Blvd, Austin',
},
{
id: 4,
name: 'Royal Blue Grocery',
address: '247 W. 3rd St, Austin',
},
{
id: 5,
name: 'Royal Blue Grocery',
address: '360 Nueces St, Austin',
},
{
id: 6,
name: 'Second Street Market',
address: '200 San Jacinto Blvd, Austin',
},
{
id: 7,
name: 'Lonestar Souvenir and Food',
address: '502 E. 6th St, Austin',
},
];
export default Observable.from(DUMMY_DATA).map(PlaceRecord).scan(pushInto, List());