Skip to content

Commit

Permalink
show-rate-products
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammadpy8 committed Aug 28, 2023
1 parent 7a01186 commit 6818979
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 41 deletions.
50 changes: 9 additions & 41 deletions src/Pages/home/Home.tsx
Original file line number Diff line number Diff line change
@@ -1,54 +1,22 @@
import React from 'react'
import React, { useContext } from 'react'
import { AiFillStar, AiOutlineStar } from 'react-icons/ai'
import { CartContext } from '../../context/CartContextProvider'
import Card from '../../components/cart/Card';

const Home = () => {

const productContext = useContext(CartContext);

return (
<>
<section>
<p className="title">All Products:</p>
</section>
<img className="index-first-bg" src="/hero-gradient.svg" alt="" />
<main className="main-index">
<div className="card">
<img
src="https://fakestoreapi.com/img/81fPKd-2AYL._AC_SL1500_.jpg"
alt=""
/>
<main>
<p>Test Title ...</p>
<div className="card-details">
<div>
<AiOutlineStar style={{ color: 'orange' }} />
<AiOutlineStar style={{ color: 'orange' }} />
<AiOutlineStar style={{ color: 'orange' }} />
<AiOutlineStar style={{ color: 'orange' }} />
<AiOutlineStar style={{ color: 'orange' }} />
</div>
<p>231$</p>
</div>
<button>Add to Basket</button>
</main>
</div>
<div className="card">
<img
src="https://fakestoreapi.com/img/81fPKd-2AYL._AC_SL1500_.jpg"
alt=""
/>
<main>
<p>Test Title ...</p>
<div className="card-details">
<div>
<AiFillStar style={{ color: 'orange' }} />
<AiFillStar style={{ color: 'orange' }} />
<AiFillStar style={{ color: 'orange' }} />
<AiFillStar style={{ color: 'orange' }} />
<AiFillStar style={{ color: 'orange' }} />
</div>
<p>231$</p>
</div>
<button>Add to Basket</button>
</main>
</div>
{
productContext.shop.map(products => <Card key={products.id} {...products} />)
}
</main>
</>
)
Expand Down
33 changes: 33 additions & 0 deletions src/components/cart/Card.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React from 'react'

import { AiFillStar, AiOutlineStar } from 'react-icons/ai'
import { Produts } from '../../types/products.types'

const Card = ({ id, title, image, price, rating: { rate } }: Produts) => {
return (
<div className="card">
<img src={image} alt="products" />
<main>
<p>{title.slice(0, 10)}</p>
<div className="card-details">
<div>
{Array(Math.ceil(rate))
.fill(0)
.map(() => (
<AiFillStar style={{ color: 'orange' }} />
))}
{Array(5 - Math.ceil(rate))
.fill(0)
.map(() => (
<AiOutlineStar style={{ color: 'orange' }} />
))}
</div>
<p>{price}$</p>
</div>
<button>Add to Basket</button>
</main>
</div>
)
}

export default Card

0 comments on commit 6818979

Please sign in to comment.