aretherecookies-mobile/js/components/ItemTile.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

55 lines
1.7 KiB
JavaScript

//@flow
import React from 'react';
import { Text, View, Image } from 'react-native';
import theme from '../ui-theme';
import { getQuantityLabelText } from '../helpers/QuantityHelpers';
import moment from 'moment';
import type { Quantity } from '../constants/QuantityConstants';
const getRelativeDateText = (lastupdated: ?number) => {
return lastupdated ? ` - ${moment(lastupdated).fromNow()}` : '';
};
export const Thumbnail = ({ thumb }: { thumb: ?string }) => (
<View
style={{
height: theme.itemTile.thumbnailSize,
width: theme.itemTile.thumbnailSize,
borderRadius: Math.round(theme.itemTile.thumbnailSize / 2),
backgroundColor: theme.itemTile.thumbnailColor,
margin: 10,
}}
>
{!!thumb && (
<Image
style={{
height: theme.itemTile.thumbnailSize,
width: theme.itemTile.thumbnailSize,
borderRadius: Math.round(theme.itemTile.thumbnailSize / 2),
}}
source={{ uri: thumb }}
/>
)}
</View>
);
export const StrongText = ({ children, style = {} }: { children?: string, style?: Object }) => {
return <Text style={{ ...theme.itemTile.itemNameStyle, ...style }}>{children}</Text>;
};
export const SubText = ({ children, style = {} }: { children?: string, style?: Object }) => {
return <Text style={{ ...theme.itemTile.itemPlaceStyle, ...style }}>{children}</Text>;
};
export const TileBox = ({ children, style = {} }: { children?: any, style?: Object }) => (
<View style={{ height: 70, flexDirection: 'row', backgroundColor: 'white', alignItems: 'center', ...style }}>
{children}
</View>
);
export const QuantityLine = ({ quantity, lastupdated }: { quantity: Quantity, lastupdated: ?number }) => (
<SubText>
{getQuantityLabelText(quantity)}
{getRelativeDateText(lastupdated)}
</SubText>
);