From b958515311d09f19bf00e3b91b65de72665a2162 Mon Sep 17 00:00:00 2001 From: Bart Akeley Date: Sun, 26 Apr 2020 12:27:24 -0500 Subject: [PATCH] unknown quantity UI --- .eslintrc | 3 +- android/app/src/main/AndroidManifest.xml | 9 +++++ js/components/ProductTile.js | 1 - js/components/ProductsList.js | 29 +++++++-------- js/components/QuantityTile.js | 47 ++++++++++++++++++++++++ js/constants/AppConstants.js | 2 +- js/pages/LoginPage.js | 16 +++++--- js/pages/ProductDetail.js | 42 ++++----------------- js/pages/ProductList.js | 2 +- js/ui-theme.js | 2 +- 10 files changed, 92 insertions(+), 61 deletions(-) create mode 100644 js/components/QuantityTile.js diff --git a/.eslintrc b/.eslintrc index 4511db5..5395b7d 100644 --- a/.eslintrc +++ b/.eslintrc @@ -18,7 +18,8 @@ "__DEV__": true }, "rules": { - "react/display-name": 1 + "react/display-name": 1, + "react/prop-types": 0 }, "settings": { "react": { diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index df0804f..df00249 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -20,6 +20,15 @@ + + + + + + diff --git a/js/components/ProductTile.js b/js/components/ProductTile.js index 48bad24..ac3c6ae 100644 --- a/js/components/ProductTile.js +++ b/js/components/ProductTile.js @@ -2,7 +2,6 @@ import React from 'react'; import { View } from 'react-native'; import { pure } from 'recompose'; import ProductRecord from '../records/ProductRecord'; -import typeof PlaceRecord from '../records/PlaceRecord'; import theme from '../ui-theme'; import { Link } from 'react-router-native'; import { routeWithTitle } from '../helpers/RouteHelpers'; diff --git a/js/components/ProductsList.js b/js/components/ProductsList.js index 86ed243..6988d80 100644 --- a/js/components/ProductsList.js +++ b/js/components/ProductsList.js @@ -1,23 +1,12 @@ -// @flow -import React, { Component } from 'react'; -import { View } from 'react-native'; +import React from 'react'; +import { View, FlatList } from 'react-native'; import { type SetSeq } from 'immutable'; import ProductRecord from '../records/ProductRecord'; import { compose, pure } from 'recompose'; import { pipe } from 'ramda'; import { withFilter } from '../enhancers/filterEnhancers'; -import FilterRecord from '../records/FilterRecord'; import { compareQuantity } from '../helpers/QuantityHelpers'; -// promote this somewhere? -type homomorph = T => T; - -type Props = { - filter: FilterRecord, - productsSeq: SetSeq, - children: (product: ProductRecord) => Component<*, *, *>, -}; - const sortByDistance = (productsSeq: SetSeq): SetSeq => { return productsSeq.sort((left, right) => left.distance - right.distance); }; @@ -33,7 +22,7 @@ const sortByQuantity = (productsSeq: SetSeq): SetSeq => { +const getSortBy = filter => { switch (filter.orderby) { case 'quantity': return sortByQuantity; @@ -47,7 +36,7 @@ const getSortBy = (filter: FilterRecord): homomorph<*> => { const intoArray = (productsSeq: SetSeq): Array => productsSeq ? productsSeq.toArray() : []; -const ProductList = (props: Props) => { +const ProductList = props => { const { filter, productsSeq, children } = props; if (!productsSeq) { @@ -59,7 +48,15 @@ const ProductList = (props: Props) => { intoArray )(productsSeq); - return {items.map(children)}; + return ( + + children(item)} + keyExtractor={item => item.id} + /> + + ); }; export default compose( diff --git a/js/components/QuantityTile.js b/js/components/QuantityTile.js new file mode 100644 index 0000000..df3b23b --- /dev/null +++ b/js/components/QuantityTile.js @@ -0,0 +1,47 @@ +import React from 'react'; +import { View, Text, Button } from 'react-native'; +import RouterButton from 'react-router-native-button'; +import { SubText } from './ItemTile'; +import { getQuantityLabelText } from '../helpers/QuantityHelpers'; +import { loginWithBackto } from '../helpers/RouteHelpers'; +import moment from 'moment'; +import theme from '../ui-theme'; + +const QuantityPanel = ({ style, isAuthed, product, onUpdatePress }) => ( + + {product.quantity ? ( + <> + + {getQuantityLabelText(product.quantity)} + + + Last updated at {moment(product.lastupdated).format('h:mm A on MMM D, YYYY')} + + + ) : ( + + Be the first to update the amount of this product. + + )} + {isAuthed && ( +