mirror of
https://gitlab.com/wheres-the-tp/ui-mobile.git
synced 2026-01-25 06:14:55 -06:00
78 lines
2.1 KiB
JavaScript
78 lines
2.1 KiB
JavaScript
// @flow
|
|
import withProps from 'recompose/withProps';
|
|
import compose from 'recompose/compose';
|
|
// import mapProps from 'recompose/mapProps';
|
|
import { path } from 'ramda';
|
|
import mapPropsStream from 'recompose/mapPropsStream';
|
|
import FoodItems$ from '../streams/FoodItemsStream';
|
|
import typeof FoodItemRecord from '../records/FoodItemRecord';
|
|
import { Map } from 'immutable';
|
|
import { getCategoryText } from '../helpers/CategoryHelpers';
|
|
|
|
export const withFoodItems = mapPropsStream(props$ =>
|
|
props$.combineLatest(FoodItems$, (props, foodItems) => {
|
|
return {
|
|
...props,
|
|
foodItemsMap: foodItems,
|
|
};
|
|
})
|
|
);
|
|
|
|
export const withFoodItemsAsSeq = mapPropsStream(props$ =>
|
|
props$.combineLatest(FoodItems$, (props, foodItems) => {
|
|
return {
|
|
...props,
|
|
foodItemsSeq: foodItems.valueSeq(),
|
|
};
|
|
})
|
|
);
|
|
|
|
export const withFoodItemIdFromRoute = withProps((props: { match: { params: { id: string } } }) => {
|
|
const id = path(['match', 'params', 'id'], props) || 0;
|
|
return { foodItemId: +id };
|
|
});
|
|
|
|
export const withFoodItem = compose(
|
|
withFoodItems,
|
|
withFoodItemIdFromRoute,
|
|
withProps((props: { foodItemsMap: Map<number, FoodItemRecord>, foodItemId: number }) => {
|
|
const { foodItemsMap, foodItemId } = props;
|
|
const foodItem = foodItemsMap.get(foodItemId);
|
|
return { foodItem };
|
|
})
|
|
);
|
|
|
|
export const withFoodItemPlaceId = withProps((props: { foodItem: FoodItemRecord }) => {
|
|
const { foodItem } = props;
|
|
return {
|
|
placeId: foodItem.placeId,
|
|
};
|
|
});
|
|
|
|
export const withFoodItemsGroupedByPlace = compose(
|
|
withFoodItems,
|
|
withProps((props: { foodItemsMap: Map<number, FoodItemRecord> }) => {
|
|
const foodItemsByPlace = props.foodItemsMap.groupBy(foodItem => foodItem.placeId);
|
|
return {
|
|
foodItemsByPlace,
|
|
};
|
|
})
|
|
);
|
|
|
|
export const withCategories = withProps((props: { foodItems: Map<string, FoodItemRecord> }) => {
|
|
const categories = props.foodItems.toSet().map(foodItem => foodItem.category).map(getCategoryText).toList();
|
|
|
|
return {
|
|
...props,
|
|
categories,
|
|
};
|
|
});
|
|
|
|
export const withDistance = withProps((props: { foodItems: Map<string, FoodItemRecord> }) => {
|
|
const distance = props.foodItems.first().get('distance', 999);
|
|
|
|
return {
|
|
...props,
|
|
distance,
|
|
};
|
|
});
|