Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(allproducts page): create all products page to display all products #13

Merged
merged 1 commit into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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