mirror of
https://gitlab.com/wheres-the-tp/ui-mobile.git
synced 2026-01-25 09:44:55 -06:00
Places list
This commit is contained in:
parent
f2c6f36920
commit
5de8c74c8e
10 changed files with 110 additions and 25 deletions
|
|
@ -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" />
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
11
js/enhancers/enhanceWithPlaces.js
Normal file
11
js/enhancers/enhanceWithPlaces.js
Normal 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,
|
||||
};
|
||||
}));
|
||||
4
js/helpers/ImmutableHelpers.js
Normal file
4
js/helpers/ImmutableHelpers.js
Normal 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);
|
||||
|
|
@ -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';
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
20
js/records/PlaceRecord.js
Normal 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');
|
||||
|
|
@ -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());
|
||||
46
js/streams/PlacesStream.js
Normal file
46
js/streams/PlacesStream.js
Normal 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());
|
||||
Loading…
Add table
Reference in a new issue