aretherecookies-mobile/js/components/QuantityPicker.js
Bart Akeley f9832afb2e show quantity and last updated in food item list
the backend is now returning quantity data merged into the food item record, so this is an easy UI update to surface it from the REST response
2017-11-19 12:22:09 -06:00

34 lines
1.2 KiB
JavaScript

// @flow
import React from 'react';
import { getQuantityDropdownText } from '../helpers/QuantityHelpers';
import { Picker, View } from 'react-native';
import theme from '../ui-theme';
import { pure } from 'recompose';
import { type Quantity, QUANTITIES } from '../constants/QuantityConstants';
import debounce from '../helpers/debounce';
const { picker: { color: selectedColor } } = theme;
const defaultColor = 'black';
const getItemColor = (selected, current) => (selected === current ? selectedColor : defaultColor);
/* eslint-disable react/display-name */
const renderQuantityItem = (selectedQuantity: Quantity) => (quantity: Quantity) => (
<Picker.Item
key={quantity}
label={getQuantityDropdownText(quantity)}
value={quantity}
color={getItemColor(selectedQuantity, quantity)}
/>
);
type QuantityPickerProps = { quantity: Quantity, onValueChange: Function, style: Object };
const QuantityPicker = pure(({ quantity, onValueChange, style }: QuantityPickerProps) => (
<View style={style}>
<Picker selectedValue={quantity} onValueChange={debounce(onValueChange)} style={{ flex: 1 }}>
{QUANTITIES.map(renderQuantityItem(quantity))}
</Picker>
</View>
));
export default QuantityPicker;