Progress with reviews
This commit is contained in:
parent
7ad02ccfe2
commit
013202546b
8 changed files with 260 additions and 394 deletions
|
|
@ -6,7 +6,9 @@ import {
|
|||
Text,
|
||||
Stack,
|
||||
Image,
|
||||
Flex,
|
||||
} from '@chakra-ui/react';
|
||||
import { BsStarFill, BsStarHalf } from 'react-icons/bs';
|
||||
|
||||
export default ({ product }) => {
|
||||
const filtered = product.images.filter((x) => !!x);
|
||||
|
|
@ -41,6 +43,16 @@ export default ({ product }) => {
|
|||
/>
|
||||
</Box>
|
||||
<Stack p={6} align="center">
|
||||
<Flex>
|
||||
{ product.overallRating
|
||||
&& new Array(Math.floor(product.overallRating)).fill('').map((x, idx) => (
|
||||
// eslint-disable-next-line react/no-array-index-key
|
||||
<BsStarFill key={`${product.name}-star-${idx}`} />
|
||||
))}
|
||||
{product.overallRating
|
||||
&& product.overallRating - Math.floor(product.overallRating) >= 0.5
|
||||
&& (<BsStarHalf />)}
|
||||
</Flex>
|
||||
<Heading fontSize="2xl" fontFamily="body" fontWeight={500}>
|
||||
{product.name}
|
||||
</Heading>
|
||||
|
|
|
|||
|
|
@ -1,38 +1,63 @@
|
|||
/* eslint-disable no-underscore-dangle */
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { Heading, Grid, GridItem } from '@chakra-ui/react';
|
||||
import { connect } from 'react-redux';
|
||||
import {
|
||||
Heading, Grid, GridItem, Box,
|
||||
} from '@chakra-ui/react';
|
||||
import { BiSearchAlt2 } from 'react-icons/bi';
|
||||
import store from '../../redux/store';
|
||||
import Card from './components/Card';
|
||||
import { Home as i18n } from '../../global/i18n';
|
||||
import Loading from '../../global/components/Loading';
|
||||
import InlineLabelInput from '../../global/components/FormControl/InlineLabelInput';
|
||||
|
||||
const Home = ({ user }) => {
|
||||
export default () => {
|
||||
const [hasLoaded, setLoaded] = useState(false);
|
||||
const [products, setProducts] = useState([]);
|
||||
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
if (hasLoaded) return () => {};
|
||||
|
||||
const _ = async (setProductsPt, setLoadedPt) => {
|
||||
const resp = await fetch('/api/v1/products');
|
||||
const data = await resp.json();
|
||||
if (resp.ok) {
|
||||
setProducts(data);
|
||||
setProductsPt(data);
|
||||
setLoadedPt(true);
|
||||
} else {
|
||||
store.dispatch({ type: 'SET_ALERT', data: { header: i18n.downloadFailedAlert.header, content: JSON.stringify(data.error) } });
|
||||
}
|
||||
})();
|
||||
};
|
||||
|
||||
_(setProducts, setLoaded);
|
||||
return () => {};
|
||||
}, [products, setProducts]);
|
||||
}, [hasLoaded, setLoaded, setProducts]);
|
||||
|
||||
if (!hasLoaded) {
|
||||
return (<Loading />);
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Heading textAlign="center">
|
||||
Hello
|
||||
{' '}
|
||||
{user?.first}
|
||||
!
|
||||
OpenCommerce Store
|
||||
</Heading>
|
||||
<Box maxW="400px" m="auto">
|
||||
<InlineLabelInput
|
||||
propChangeEvt={() => {}}
|
||||
propKeyPressEvt={() => {}}
|
||||
propSubmitEvt={() => {}}
|
||||
type="text"
|
||||
labelBgColor="green.400"
|
||||
labelFgColor="white"
|
||||
labelIcon={(<BiSearchAlt2 />)}
|
||||
labelText="Search.."
|
||||
error={null}
|
||||
/>
|
||||
</Box>
|
||||
|
||||
<Grid templateColumns="repeat(auto-fit, minmax(384px, 1fr));" rowGap={6}>
|
||||
<hr />
|
||||
|
||||
<Grid templateColumns="repeat(auto-fit, minmax(384px, 1fr));" rowGap={6} mt={2}>
|
||||
{products.map((x) => (
|
||||
<GridItem key={x._id}>
|
||||
<Card product={x} />
|
||||
|
|
@ -42,6 +67,3 @@ const Home = ({ user }) => {
|
|||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const mapStateToProps = ({ user }) => ({ user });
|
||||
export default connect(mapStateToProps)(Home);
|
||||
|
|
|
|||
Loading…
Reference in a new issue