Skip to content

Commit

Permalink
Merge pull request #13 from 202306-NEA-DZ-FEW/11-feature-all_products…
Browse files Browse the repository at this point in the history
…-page

feat(allproducts page): create all products page to display all products
  • Loading branch information
hasnahadd authored Sep 28, 2023
2 parents 3b66942 + 4425a52 commit 8db4716
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
3 changes: 0 additions & 3 deletions src/components/ShoppingCard/ShoppingCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ export default function ShoppingCard({ id, title, image, price, rating }) {
<img
src={image}
alt={title}

style={{ width: "60%", height: "250px", padding: "1rem" }}
/>
</figure>
<div className="card-body text-center">
<h2 className="card-title text-text-brown mb-2 ">

{title.length > 25 ? `${title.slice(0, 25)}...` : title}
</h2>
<StarRating rating={rating.rate} />
Expand All @@ -28,7 +26,6 @@ export default function ShoppingCard({ id, title, image, price, rating }) {
</button>

<p className="font-bold text-xl">{price}$</p>

</div>
</div>
</div>
Expand Down
5 changes: 0 additions & 5 deletions src/pages/products/index.js

This file was deleted.

28 changes: 28 additions & 0 deletions src/pages/products/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import ShoppingCard from "@/components/ShoppingCard/ShoppingCard"

import { useEffect, useState } from "react"

const AllProducts = () => {
const [products, setProducts] = useState([])

function fetchProducts() {
fetch("https://fakestoreapi.com/products")
.then((res) => res.json())
.then((products) => setProducts(products))
}
useEffect(() => {
fetchProducts()
}, [])

return (
<div>
<h1 className="text-3xl text-center font-semibold py-2">All Products</h1>
<div className="grid grid-cols-3 gap-6 mx-auto p-16 justify-center bg-slate-100">
{products.map((product) => {
return <ShoppingCard key={product.id} {...product} />
})}
</div>
</div>
)
}
export default AllProducts

0 comments on commit 8db4716

Please sign in to comment.