mirror of
https://gitlab.com/wheres-the-tp/ui-mobile.git
synced 2026-01-25 10:34:56 -06:00
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
55 lines
1.7 KiB
JavaScript
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>
|
|
);
|